篆体字作品 | 篆体字知识 | 加入收藏 篆体字转换器软件可转换多种篆体字在线预览 网页版 V2.0
篆体字转换器

当前位置:篆体字网 > 知识库 >

scheduledthreadpoolexecutor

时间:2024-01-01 01:41:31 编辑:篆字君 来源:篆体字网

Public Methodsvoidexecute(Runnable command)

Executes with zero required delay.

booleangetContinueExistingPeriodicTasksAfterShutdownPolicy()

Gets the policy on whether to continue executing existing periodic tasks even when this executor has been .

获取有关在此执行程序已shutdown 的情况下、是否继续执行现有定期任务的策略。

booleangetExecuteExistingDelayedTasksAfterShutdownPolicy()

Gets the policy on whether to execute existing delayed tasks even when this executor has been .

获取有关在此执行程序已 shutdown 的情况下是否继续执行现有延迟任务的策略。

BlockingQueuegetQueue()

Returns the task queue used by this executor.

ScheduledFutureschedule(Runnable command, long delay, TimeUnit unit)

Creates and executes a one-shot action that becomes enabled after the given delay.

ScheduledFutureschedule(Callablecallable, long delay, TimeUnit unit)

Creates and executes a ScheduledFuture that becomes enabled after the given delay.

ScheduledFuturescheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit)

Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is executions will commence after initialDelay then initialDelay+period, then initialDelay + 2 * period, and so on.

ScheduledFuturescheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit)

Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given delay between the termination of one execution and the commencement of the next.

voidsetContinueExistingPeriodicTasksAfterShutdownPolicy(boolean value)

Sets the policy on whether to continue executing existing periodic tasks even when this executor has been .

设置有关在此执行程序已 shutdown 的情况下是否继续执行现有定期任务的策略。

voidsetExecuteExistingDelayedTasksAfterShutdownPolicy(boolean value)

Sets the policy on whether to execute existing delayed tasks even when this executor has been .

设置有关在此执行程序已 shutdown 的情况下是否继续执行现有延迟任务的策略。

voidshutdown()

Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.

ListshutdownNow()

Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.

Futuresubmit(Runnable task, T result)

Submits a Runnable task for execution and returns a Future representing that task.

Futuresubmit(Callabletask)

Submits a value-returning task for execution and returns a Future representing the pending results of the task.

Futuresubmit(Runnable task)

Submits a Runnable task for execution and returns a Future representing that task.

Protected MethodsRunnableScheduledFuturedecorateTask(Runnable runnable, RunnableScheduledFuturetask)

Modifies or replaces the task used to execute a runnable.

重写该函数来,以用个性化的RunnableScheduledFuture来包装runnable任务,task是ScheduledThreadPoolExecutor提供默认的默认的对runnable的RunnableSheduledFuture包装,即ScheduledFutureTask对象。

RunnableScheduledFuturedecorateTask(Callablecallable, RunnableScheduledFuturetask)

Modifies or replaces the task used to execute a callable.

重写该函数来,以用个性化的RunnableScheduledFuture来包装callable任务,task是ScheduledThreadPoolExecutor提供默认的默认的对callable的RunnableSheduledFuture包装,即ScheduledFutureTask对象。

更多内容请参考《ThreadPoolExecutor》和《ScheduledExecutorService》
Timer与ScheduledThreadPoolExecutor的区别
Timer对调度的支持是基于绝对时间的,因此任务对系统时间的改变是敏感的;而ScheduledThreadPoolExecutor支持相对时间。
Timer使用单线程方式来执行所有的TimerTask,如果某个TimerTask很耗时则会影响到其他TimerTask的执行;
而ScheduledThreadPoolExecutor则可以构造一个固定大小的线程池来执行任务。
Timer 不会捕获由TimerTask抛出的未检查异常,故当有异常抛出时,Timer会终止,导致未执行完的TimerTask不再执行,新的 TimerTask也不能被调度;
ScheduledThreadPoolExecutor对这个问题进行了妥善的处理,不会影响其他任务的执行。

Copyright:2021-2023 篆体字转换器 www.dddtedu.com All rights reserved.