ThreadPoolExecutor
核心属性
corePoolSize
maximumPoolSize
keepAliveTime
TimeUnit unit
BlockingQueue<Runnable> workQueue
ThreadFactory threadFactory
RejectedExecutionHandler handler
AbortPolicy
CallerRunsPolicy
DiscardOldestPolicy
DiscardPolicy
实现RejectedExecutionHandler接口自定义策略
核心方法
exec():提交不需要返回自的任务<br>
submit():提交返回Future对象任务
shutdown():线程池置为SHUTDOWN状态,并等待线程执行interrupt()方法
shutdownNow():线程池置为STOP状态,尝试暂停所有任务
线程池分类
newCacheThreadPool()
newFixedThreadPool(int n)
newScheduledThreadPool(int n)
newSingleThreadExecutor()