線程池創建的四種
通過Executors線程池創建的四種方法分別爲:
newCachedThreadPool:創建一個可緩存線程池,如果線程池長度超過處理需要,可靈活回收空閒線程,若無可回收,則新建線程。
newFixedThreadPool:創建一個定長線程池,可控制線程最大併發數,超出的線程會在隊列中等待。
newScheduledThreadPool:創建一個定長線程池,支持定時及週期性任務執行。
newSingleThreadExecutor:創建一個單線程化的線程池,它只會用唯一的工作線程來執行任務,保證所有任務按照指定順序(FIFO, LIFO, 優先級)執行。
public class ThreadPoolExecutor extends AbstractExecutorService{//第一個構造方法public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue) { this(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, Executors.defaultThreadFactory(), defaultHandler); }//第二個構造方法public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory) { this(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, defaultHandler); }//第三個構造方法public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, RejectedExecutionHandler handler) { this(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, Executors.defaultThreadFactory(), handler); }//第四個也是真正的初始化構造函數public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory, RejectedExecutionHandler handler) { if (corePoolSize < 0 || maximumPoolSize <= 0 || maximumPoolSize < corePoolSize || keepAliveTime < 0) throw new IllegalargumentException(); if (workQueue == null || threadFactory == null || handler == null) throw new NullPointerException(); this.corePoolSize = corePoolSize; this.maximumPoolSize = maximumPoolSize; this.workQueue = workQueue; this.keepAliveTime = unit.toNanos(keepAliveTime); this.threadFactory = threadFactory; this.handler = handler; }}
-
手機qq如何判斷好友是否隱身
1、在手機桌面上打開【QQ】,進入主界面,點擊【聯繫人】選項。然後點擊要判斷是否隱身的好友。在他的詳細資料界面,點擊【發消息】。進入聊天界面後,點擊右上角【通話】。2、在通話方式中,選擇【語音通話】功能。如果顯示【等待對方接聽】,那他就在隱身。顯示爲【對方...
-
載人火箭頂部有一個尖頂叫什麼塔
1、載人火箭頂部有一個尖頂叫逃逸塔,又名逃生塔,裝在飛船頂端,從遠處看像是火箭上的避雷針,與一般火箭圓錐形的頭部很不相同。2、由塔架、逃逸發動機和分離發動機(均爲固體火箭發動機)組成,發生緊急情況時,逃逸發動機迅速點火,使航天員座艙(返回艙)與固體火箭分離,迅速脫離...
-
微博如何屏蔽廣告
微博裏面經常出現廣告是一件很煩心的事情,不過,有很多的方法可以屏蔽微博廣告。首先打開自己的微博,進入微博首頁,然後找到自己不喜歡看的微博廣告,在右側有一個倒三角的按鈕,點擊進入,我們點擊想要屏蔽的經常發廣告的微博,然後點擊確定就可以了。也可以屏蔽來自某個客...
-
移動硬盤壞了上面的數據能恢復嗎
移動硬盤壞了數據能否恢復要看硬盤損壞的程度,如果壞的程度不嚴重,可以通過電腦自動修復。通過電腦自動修復硬盤的方法比較簡單,首先將移動硬盤連接到電腦上,選中移動硬盤,右鍵點擊【屬性】-【工具】-【差錯】-【開始檢查】,勾選【自動修復文件系統錯誤】和【掃描並...