你是否正在寻找关于scheduledthreadpoolexecutor的内容?让我把最俱价值的东西奉献给你:
ThreadPoolExecutor,它可另行安排在给定的延迟后运行命令,或者定期执行命令。需要多个辅助线程时,或者要求 ThreadPoolExecutor 具有额外的灵活性或功能时,此类要优于 Timer。
一旦启用已延迟的任务就执行它,但是有关何时启用,启用后何时执行则没有任何实时保证。按照提交的先进先出 (FIFO) 顺序来启用那些被安排在同一执行时间的任务。
虽然此类继承自 ThreadPoolExecutor,但是几个继承的调整方法对此类并无作用。特别是,因为它作为一个使用 corePoolSize 线程和一个无界队列的固定大小的池,所以调整 maximumPoolSize 没有什么效果。
扩展注意事项:此类重写 AbstractExecutorService 的 submit 方法,以生成内部对象控制每个任务的延迟和调度。若要保留功能性,子类中任何进一步重写的这些方法都必须调用超类版本,超类版本有效地禁用附加任务的定制。但是,此类提供替代受保护的扩展方法 decorateTask(为 Runnable 和 Callable 各提供一种版本),可定制用于通过 execute、submit、schedule、scheduleAtFixedRate 和 scheduleWithFixedDelay 进入的执行命令的具体任务类型。默认情况下,ScheduledThreadPoolExecutor 使用一个扩展 FutureTask 的任务类型。但是,可以使用下列形式的子类修改或替换该类型。 public class CustomScheduledExecutor extends scheduledthreadpoolexecutor { static class CustomTask<V> implements RunnableScheduledFuture<V> { ... } protected <V> RunnableScheduledFuture<V> decorateTask( Runnable r, RunnableScheduledFuture<V> task) { return new CustomTask<V>(r, task); } protected <V> RunnableScheduledFuture<V> decorateTask( Callable<V> c, RunnableScheduledFuture<V> task) { return new CustomTask<V>(c, task); } // ... add constructors, etc. }
嵌套类摘要
从类 java.util.concurrent.ThreadPoolExecutor 继承的嵌套类/接口
ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicy
构造方法摘要
scheduledthreadpoolexecutor(intcorePoolSize)
使用给定核心池大小创建一个新 scheduledthreadpoolexecutor。
scheduledthreadpoolexecutor(intcorePoolSize,
RejectedExecutionHandlerhandler)
使用给定初始参数创建一个新 scheduledthreadpoolexecutor。
scheduledthreadpoolexecutor(intcorePoolSize,
ThreadFactorythreadFactory)
使用给定的初始参数创建一个新 scheduledthreadpoolexecutor。
scheduledthreadpoolexecutor(intcorePoolSize,
ThreadFactorythreadFactory,
RejectedExecutionHandlerhandler)
使用给定初始参数创建一个新 scheduledthreadpoolexecutor。
方法摘要
protected
<V> RunnableScheduledFuture<V>
decorateTask(Callable<V>callable, RunnableScheduledFuture<V>task)protected
<V> RunnableScheduledFuture<V>
decorateTask(Runnablerunnable, RunnableScheduledFuture<V>task)
void
execute(Runnablecommand)
使用所要求的零延迟执行命令。
boolean
getContinueExistingPeriodicTasksAfterShutdownPolicy()
获取有关在此执行程序已 shutdown 的情况下、是否继续执行现有定期任务的策略。
boolean
getExecuteExistingDelayedTasksAfterShutdownPolicy()
获取有关在此执行程序已 shutdown 的情况下是否继续执行现有延迟任务的策略。
BlockingQueue<Runnable>
getQueue()
返回此执行程序使用的任务队列。
boolean
remove(Runnabletask)
从执行程序的内部队列中移除此任务(如果存在),从而如果尚未开始,则其不再运行。
<V> ScheduledFuture<V>
schedule(Callable<V>callable, longdelay, TimeUnitunit)
ScheduledFuture<?>
schedule(Runnablecommand,
longdelay,
TimeUnitunit)
创建并执行在给定延迟后启用的一次性操作。
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-17399-1.html
美利坚万岁
早上喝两包压压惊