参数:corePoolSize - 池中所保存的线程数(包括空闲线程)threadFactory - 执行程序创建新线程时使用的工厂handler - 由于超出线程范围和队列容量而使执行被阻塞时所使用的处理程序
抛出:
IllegalArgumentException - 如果 corePoolSize < 0
NullPointerException - 如果 threadFactory 或处理程序为 null
方法详细信息
remove
public boolean remove(Runnabletask)
从类 ThreadPoolExecutor 复制的描述
从执行程序的内部队列中移除此任务(如果存在),从而如果尚未开始,则其不再运行。
此方法可用作取消方案的一部分。它可能无法移除在放置到内部队列之前已经转换为其他形式的任务。例如,使用 submit 输入的任务可能被转换为维护 Future 状态的形式。但是,在此情况下,ThreadPoolExecutor.purge() 方法可用于移除那些已被取消的 Future。
覆盖:类 ThreadPoolExecutor 中的 remove
参数:task - 要移除的任务
返回:如果已经移除任务,则返回 true
decorateTask
protected <V> RunnableScheduledFuture<V> decorateTask(Runnablerunnable,
RunnableScheduledFuture<V>task)
修改或替换用于执行 runnable 的任务。此方法可重写用于管理内部任务的具体类。默认实现只返回给定任务。
参数:runnable - 所提交的 Runnabletask - 执行 runnable 所创建的任务
返回:可以执行 runnable 的任务从以下版本开始:
1.6
decorateTask
protected <V> RunnableScheduledFuture<V> decorateTask(Callable<V>callable,
RunnableScheduledFuture<V>task)
修改或替换用于执行 callable 的任务。此方法可重写用于管理内部任务的具体类。默认实现返回给定任务。
参数:callable - 所提交的 Callabletask - 执行 callable 所创建的任务
返回:可以执行 callable 的任务从以下版本开始:
1.6
schedule
public ScheduledFuture<?> schedule(Runnablecommand,
longdelay,
TimeUnitunit)
从接口 ScheduledExecutorService 复制的描述
创建并执行在给定延迟后启用的一次性操作。
指定者:接口 ScheduledExecutorService 中的 schedule
参数:command - 要执行的任务delay - 从现在开始延迟执行的时间unit - 延迟参数的时间单位
返回:表示挂起任务完成的 ScheduledFuture,并且其 get() 方法在完成后将返回 null
schedule
public <V> ScheduledFuture<V> schedule(Callable<V>callable,
longdelay,
TimeUnitunit)
从接口 ScheduledExecutorService 复制的描述
创建并执行在给定延迟后启用的 ScheduledFuture。
指定者:接口 ScheduledExecutorService 中的 schedule
参数:callable - 要执行的功能delay - 从现在开始延迟执行的时间unit - 延迟参数的时间单位
返回:可用于提取结果或取消的 ScheduledFuture
scheduleAtFixedRate
public ScheduledFuture<?> scheduleAtFixedRate(Runnablecommand,
longinitialDelay,
longperiod,
TimeUnitunit)
从接口 ScheduledExecutorService 复制的描述
创建并执行一个在给定初始延迟后首次启用的定期操作,后续操作具有给定的周期;也就是将在 initialDelay 后开始执行,然后在 initialDelay+period 后执行,接着在 initialDelay + 2 * period 后执行,依此类推,。如果任务的任何一个执行遇到异常,则后续执行都会被取消。否则,只能通过执行程序的取消或终止方法来终止该任务。如果此任务的任何一个执行要花费比其周期更长的时间,则将推迟后续执行,但不会同时执行。
指定者:接口 ScheduledExecutorService 中的 scheduleAtFixedRate
参数:command - 要执行的任务initialDelay - 首次执行的延迟时间period - 连续执行之间的周期unit - initialDelay 和 period 参数的时间单位
返回:表示挂起任务完成的 ScheduledFuture,并且其 get() 方法在取消后将抛出异常
scheduleWithFixedDelay
public ScheduledFuture<?> scheduleWithFixedDelay(Runnablecommand,
longinitialDelay,
longdelay,
TimeUnitunit)
从接口 ScheduledExecutorService 复制的描述
创建并执行一个在给定初始延迟后首次启用的定期操作,随后,在每一次执行终止和下一次执行开始之间都存在给定的延迟。如果任务的任一执行遇到异常,就会取消后续执行。否则,只能通过执行程序的取消或终止方法来终止该任务。
指定者:接口 ScheduledExecutorService 中的 scheduleWithFixedDelay
参数:command - 要执行的任务initialDelay - 首次执行的延迟时间delay - 一次执行终止和下一次执行开始之间的延迟unit - initialDelay 和 delay 参数的时间单位
返回:表示挂起任务完成的 ScheduledFuture,并且其 get() 方法在取消后将抛出异常
execute
public void execute(Runnablecommand)
使用所要求的零延迟执行命令。这在效果上等同于调用 schedule(command, 0, anyUnit)。注意,对由 shutdownNow 所返回的队列和列表的检查将访问零延迟的 ScheduledFuture,而不是 command 本身。
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-17399-3.html
但是好费电