Executor框架?
靈活強大的異步框架,支持多種不同類型的任務執行策略,將任務提交過程與執行過程分離開來,解耦開發
Executor 接口 提供了提交任務的方法executor ?
ExecutorService 子接口 提供了生命周期管理方法,submit(Runnable),shutdown() ,shutdownNow()
?AbstractExecutorService ?ThreadPoolExecutor ?線程池利用工廠類創建各種線程池
ScheduledThreadPoolExecutor 可定時調度任務的線程池
ThreadPoolExecutor 主要參數
corePoolSize ?核心線程數
maximumPoolSize 最大線程數
long keepAliveTime ?非核心空閑線程存活時間
BlockingQueue<Runnable> ? workQueue ?保存任務的阻塞隊列
handle ? 拒絕策略
(1)ThreadPoolExecutor
newFixedThreadPool(n,n,0L,new linkedBlockingQueue<Runnable>);可重用的固定線程數線程池
newSingleThreadPoolExecutor(1,1,0L,linkedBlockingQueue<Runnable>);單線程的線程池適用于保證順序的執行各個任務
newCachedThreadPool(0,Integer.Max_value,60L,synchronousQueue<Runnable>);
大小無界的線程池,適用于執行很多短期異步任務的小程序
(2)ScheduledThreadPoolExecutor
newSingleThreadPoolExecutor(1,1,0L,DelayedWorkQueue);可調度單線程線程池
newScheduledThreadPoolExecutor();可調度的多線程池
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。