ScheduledThreadPoolExecutor是由Doug Lea大神出品,用于执行延时任务的线程池。
public class ScheduledThreadPoolExecutor
extends ThreadPoolExecutor
implements ScheduledExecutorService {
}
ScheduledThreadPoolExecutor继承了ThreadPoolExecutor,并自定义了延迟阻塞队列DelayedWorkQueue用于存放延时任务,同时使用ScheduledFutureTask来包装待执行的任务。
ScheduledFutureTask
private class ScheduledFutureTask<V>
extends FutureTask<V> implements RunnableScheduledFuture<V> {
}
public class FutureTask<V> implements RunnableFuture<V>{}
public interface RunnableScheduledFuture<V> extends RunnableFuture<V>, ScheduledFuture<V>{}
// 因为继承了Delayed接口,所以包装后的任务才可以添加到延时队列中
public