java 线程池 两个定时方法的参数意义

构造方法详细信息

ScheduledThreadPoolExecutor

public ScheduledThreadPoolExecutor(int corePoolSize)
使用给定核心池大小创建一个新 ScheduledThreadPoolExecutor。

参数:
corePoolSize - 池中所保存的线程数(包括空闲线程)
抛出:
IllegalArgumentException - 如果  corePoolSize < 0

ScheduledThreadPoolExecutor

public ScheduledThreadPoolExecutor(int corePoolSize,
                                   ThreadFactory threadFactory)
使用给定的初始参数创建一个新 ScheduledThreadPoolExecutor。

参数:
corePoolSize - 池中所保存的线程数(包括空闲线程)
threadFactory - 执行程序创建新线程时使用的工厂
抛出:
IllegalArgumentException - 如果  corePoolSize < 0
NullPointerException - 如果 threadFactory 为 null

ScheduledThreadPoolExecutor

public ScheduledThreadPoolExecutor(int corePoolSize,
                                   RejectedExecutionHandler handler)
使用给定初始参数创建一个新 ScheduledThreadPoolExecutor。

参数:
corePoolSize - 池中所保存的线程数(包括空闲线程)
handler - 由于超出线程范围和队列容量而使执行被阻塞时所使用的处理程序
抛出:
IllegalArgumentException - 如果  corePoolSize < 0
NullPointerException - 如果处理程序为 null

ScheduledThreadPoolExecutor

public ScheduledThreadPoolExecutor(int corePoolSize,
                                   ThreadFactory threadFactory,
                                   RejectedExecutionHandler handler)
使用给定初始参数创建一个新 ScheduledThreadPoolExecutor。

参数:
corePoolSize - 池中所保存的线程数(包括空闲线程)
threadFactory - 执行程序创建新线程时使用的工厂
handler - 由于超出线程范围和队列容量而使执行被阻塞时所使用的处理程序
抛出:
IllegalArgumentException - 如果  corePoolSize < 0
NullPointerException - 如果 threadFactory 或处理程序为 null
方法详细信息

remove

public boolean remove(Runnable task)
从类 ThreadPoolExecutor 复制的描述
从执行程序的内部队列中移除此任务(如果存在),从而如果尚未开始,则其不再运行。

此方法可用作取消方案的一部分。它可能无法移除在放置到内部队列之前已经转换为其他形式的任务。例如,使用 submit 输入的任务可能被转换为维护 Future 状态的形式。但是,在此情况下,ThreadPoolExecutor.purge() 方法可用于移除那些已被取消的 Future。

覆盖:
类  ThreadPoolExecutor 中的  remove
参数:
task - 要移除的任务
返回:
如果已经移除任务,则返回 true

decorateTask

protected <V> RunnableScheduledFuture<V> decorateTask(Runnable runnable,
                                                      RunnableScheduledFuture<V> task)
修改或替换用于执行 runnable 的任务。此方法可重写用于管理内部任务的具体类。默认实现只返回给定任务。

参数:
runnable - 所提交的 Runnable
task - 执行 runnable 所创建的任务
返回:
可以执行 runnable 的任务
从以下版本开始:
1.6

decorateTask

protected <V> RunnableScheduledFuture<V> decorateTask(Callable<V> callable,
                                                      RunnableScheduledFuture<V> task)
修改或替换用于执行 callable 的任务。此方法可重写用于管理内部任务的具体类。默认实现返回给定任务。

参数:
callable - 所提交的 Callable
task - 执行 callable 所创建的任务
返回:
可以执行 callable 的任务
从以下版本开始:
1.6

schedule

public ScheduledFuture<?> schedule(Runnable command,
                                   long delay,
                                   TimeUnit unit)
从接口 ScheduledExecutorService 复制的描述
创建并执行在给定延迟后启用的一次性操作。

指定者:
接口  ScheduledExecutorService 中的  schedule
参数:
command - 要执行的任务
delay - 从现在开始延迟执行的时间
unit - 延迟参数的时间单位
返回:
表示挂起任务完成的 ScheduledFuture,并且其  get() 方法在完成后将返回  null

schedule

public <V> ScheduledFuture<V> schedule(Callable<V> callable,
                                       long delay,
                                       TimeUnit unit)
从接口 ScheduledExecutorService 复制的描述
创建并执行在给定延迟后启用的 ScheduledFuture。

指定者:
接口  ScheduledExecutorService 中的  schedule
参数:
callable - 要执行的功能
delay - 从现在开始延迟执行的时间
unit - 延迟参数的时间单位
返回:
可用于提取结果或取消的 ScheduledFuture

scheduleAtFixedRate

public ScheduledFuture<?> scheduleAtFixedRate(Runnable command,
                                              long initialDelay,
                                              long period,
                                              TimeUnit unit)
从接口 ScheduledExecutorService 复制的描述
创建并执行一个在给定初始延迟后首次启用的定期操作,后续操作具有给定的周期;也就是将在  initialDelay 后开始执行,然后在  initialDelay+period 后执行,接着在  initialDelay + 2 * period 后执行,依此类推。如果任务的任何一个执行遇到异常,则后续执行都会被取消。否则,只能通过执行程序的取消或终止方法来终止该任务。如果此任务的任何一个执行要花费比其周期更长的时间,则将推迟后续执行,但不会同时执行。

指定者:
接口  ScheduledExecutorService 中的  scheduleAtFixedRate
参数:
command - 要执行的任务
initialDelay - 首次执行的延迟时间
period - 连续执行之间的周期
unit - initialDelay 和 period 参数的时间单位
返回:
表示挂起任务完成的 ScheduledFuture,并且其  get() 方法在取消后将抛出异常

scheduleWithFixedDelay

public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command,
                                                 long initialDelay,
                                                 long delay,
                                                 TimeUnit unit)
从接口 ScheduledExecutorService 复制的描述
创建并执行一个在给定初始延迟后首次启用的定期操作,随后,在每一次执行终止和下一次执行开始之间都存在给定的延迟。如果任务的任一执行遇到异常,就会取消后续执行。否则,只能通过执行程序的取消或终止方法来终止该任务。

指定者:
接口  ScheduledExecutorService 中的  scheduleWithFixedDelay
参数:
command - 要执行的任务
initialDelay - 首次执行的延迟时间
delay - 一次执行终止和下一次执行开始之间的延迟
unit - initialDelay 和 delay 参数的时间单位
返回:
表示挂起任务完成的 ScheduledFuture,并且其  get() 方法在取消后将抛出异常

execute

public void execute(Runnable command)
使用所要求的零延迟执行命令。这在效果上等同于调用  schedule(command, 0, anyUnit)。注意,对由  shutdownNow 所返回的队列和列表的检查将访问零延迟的  ScheduledFuture,而不是  command 本身。

指定者:
接口  Executor 中的  execute
覆盖:
类  ThreadPoolExecutor 中的  execute
参数:
command - 要执行的任务。
抛出:
 -  RejectedExecutionHandler 随意决定的 RejectedExecutionException,如果由于执行程序已关闭而无法接受要执行的任务 。
NullPointerException - 如果 command 为 null。

submit

public Future<?> submit(Runnable task)
从接口 ExecutorService 复制的描述
提交一个 Runnable 任务用于执行,并返回一个表示该任务的 Future。该 Future 的  get 方法在 成功 完成时将会返回  null

指定者:
接口  ExecutorService 中的  submit
覆盖:
类  AbstractExecutorService 中的  submit
参数:
task - 要提交的任务
返回:
表示任务等待完成的 Future

submit

public <T> Future<T> submit(Runnable task,
                            T result)
从接口 ExecutorService 复制的描述
提交一个 Runnable 任务用于执行,并返回一个表示该任务的 Future。该 Future 的  get 方法在成功完成时将会返回给定的结果。

指定者:
接口  ExecutorService 中的  submit
覆盖:
类  AbstractExecutorService 中的  submit
参数:
task - 要提交的任务
result - 返回的结果
返回:
表示任务等待完成的 Future

submit

public <T> Future<T> submit(Callable<T> task)
从接口 ExecutorService 复制的描述
提交一个返回值的任务用于执行,返回一个表示任务的未决结果的 Future。该 Future 的  get 方法在成功完成时将会返回该任务的结果。

如果想立即阻塞任务的等待,则可以使用 result = exec.submit(aCallable).get(); 形式的构造。

注:Executors 类包括了一组方法,可以转换某些其他常见的类似于闭包的对象,例如,将 PrivilegedAction 转换为 Callable 形式,这样就可以提交它们了。

指定者:
接口  ExecutorService 中的  submit
覆盖:
类  AbstractExecutorService 中的  submit
参数:
task - 要提交的任务
返回:
表示任务等待完成的 Future

setContinueExistingPeriodicTasksAfterShutdownPolicy

public void setContinueExistingPeriodicTasksAfterShutdownPolicy(boolean value)
设置有关在此执行程序已  shutdown 的情况下是否继续执行现有定期任务的策略。在这种情况下,仅在执行  shutdownNow 时,或者在执行程序已关闭、将策略设置为  false 后才终止这些任务。此值默认为 false。

参数:
value - 如果为 true,则在关闭后继续执行;否则不执行。
另请参见:
getContinueExistingPeriodicTasksAfterShutdownPolicy()

getContinueExistingPeriodicTasksAfterShutdownPolicy

public boolean getContinueExistingPeriodicTasksAfterShutdownPolicy()
获取有关在此执行程序已  shutdown 的情况下、是否继续执行现有定期任务的策略。在这种情况下,仅在执行  shutdownNow 时,或者在执行程序已关闭时将策略设置为  false 后才终止这些任务。此值默认为 false。

返回:
如果关闭后继续执行,则返回 true。
另请参见:
setContinueExistingPeriodicTasksAfterShutdownPolicy(boolean)

setExecuteExistingDelayedTasksAfterShutdownPolicy

public void setExecuteExistingDelayedTasksAfterShutdownPolicy(boolean value)
设置有关在此执行程序已  shutdown 的情况下是否继续执行现有延迟任务的策略。在这种情况下,仅在执行  shutdownNow 时,或者在执行程序已关闭、将策略设置为  false 后才终止这些任务。此值默认为 true。

参数:
value - 如果为 true,则在关闭后执行;否则不执行。
另请参见:
getExecuteExistingDelayedTasksAfterShutdownPolicy()

getExecuteExistingDelayedTasksAfterShutdownPolicy

public boolean getExecuteExistingDelayedTasksAfterShutdownPolicy()
获取有关在此执行程序已  shutdown 的情况下是否继续执行现有延迟任务的策略。在这种情况下,仅在执行  shutdownNow 时,或者在执行程序已关闭时将策略设置为  false 后才终止这些任务。此值默认为 true。

返回:
如果关闭后执行,则返回 true
另请参见:
setExecuteExistingDelayedTasksAfterShutdownPolicy(boolean)

shutdown

public void shutdown()
在以前已提交任务的执行中发起一个有序的关闭,但是不接受新任务。如果已将  ExecuteExistingDelayedTasksAfterShutdownPolicy 设置为  false,则取消尚未超出其延迟的现有延迟任务。并且除非已将  ContinueExistingPeriodicTasksAfterShutdownPolicy 设置为  true,否则将取消现有定期任务的后续执行。

指定者:
接口  ExecutorService 中的  shutdown
覆盖:
类  ThreadPoolExecutor 中的  shutdown

shutdownNow

public List<Runnable> shutdownNow()
尝试停止所有正在执行的任务、暂停等待任务的处理,并返回等待执行的任务列表。

虽然尽最大努力,但并不保证可以停止处理正在执行的任务。此实现通过 Thread.interrupt() 取消任务,所以任何无法响应中断的任务都可能永远无法终止。

指定者:
接口  ExecutorService 中的  shutdownNow
覆盖:
类  ThreadPoolExecutor 中的  shutdownNow
返回:
从未开始执行的任务列表。此列表中的每个元素都是一个  ScheduledFuture,包括用  execute 所提交的那些任务,出于安排的目的,这些任务用作零延迟  ScheduledFuture 的基础。
抛出:
SecurityException - 如果安全管理器存在并且关闭此 ExecutorService 可能操作某些不允许调用者修改的线程(因为它没有  RuntimePermission ("modifyThread")),或者安全管理器的  checkAccess 方法拒绝访问。

getQueue

public BlockingQueue<Runnable> getQueue()
返回此执行程序使用的任务队列。此队列中的每个元素都是一个  ScheduledFuture,包括用  execute 所提交的那些任务,出于安排的目的,这些任务用作零延迟  ScheduledFuture 的基础。 无法 保证对此队列进行迭代的迭代器会以任务执行的顺序遍历各任务。

覆盖:
类  ThreadPoolExecutor 中的  getQueue
返回:
任务队列。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值