![什么是java線程池框架_第1頁](http://file4.renrendoc.com/view/f7f7a2e252462d57c32ff331ef41d4a9/f7f7a2e252462d57c32ff331ef41d4a91.gif)
![什么是java線程池框架_第2頁](http://file4.renrendoc.com/view/f7f7a2e252462d57c32ff331ef41d4a9/f7f7a2e252462d57c32ff331ef41d4a92.gif)
![什么是java線程池框架_第3頁](http://file4.renrendoc.com/view/f7f7a2e252462d57c32ff331ef41d4a9/f7f7a2e252462d57c32ff331ef41d4a93.gif)
下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、什么是java線程池框架什么是java線程池框架多線程是程序員面試時常常會面對的問題,對多線程概念的掌握和理解水平,也常常被用來衡量一個人的.編程實力。不錯,普通的多線程已經(jīng)不容易了。一、線程池結(jié)構(gòu)圖二、示例定義線程接口6public class MyThread extends Thread Overridepublicvoid run() System.out.println(Thread.currentThread().getName() + 正在執(zhí)行);1:newSingleThreadExecutor10ExecutorService pool = Executors. newSin
2、gleThreadExecutor();Thread t1 = new MyThread();Thread t2 = new MyThread();Thread t3 = new MyThread();/將線程放入池中進(jìn)行執(zhí)行pool.execute(t1);pool.execute(t2);pool.execute(t3);/關(guān)閉線程池pool.shutdown();輸入結(jié)果:3pool-1-thread-1正在執(zhí)行pool-1-thread-1正在執(zhí)行pool-1-thread-1正在執(zhí)行2:newFixedThreadPool13ExecutorService pool = Execut
3、ors.newFixedThreadPool(3);Thread t1 = new MyThread();Thread t2 = new MyThread();Thread t3 = new MyThread();Thread t4 = new MyThread();Thread t5 = new MyThread();/將線程放入池中進(jìn)行執(zhí)行pool.execute(t1);pool.execute(t2);pool.execute(t3);pool.execute(t4);pool.execute(t5);pool.shutdown();輸入結(jié)果:4pool-1-thread-1正在執(zhí)行p
4、ool-1-thread-2正在執(zhí)行pool-1-thread-1正在執(zhí)行pool-1-thread-2正在執(zhí)行3 :newCachedThreadPool14ExecutorService pool = Executors.newCachedThreadPool();Thread t1 = new MyThread();Thread t2 = new MyThread();Thread t3 = new MyThread();Thread t4 = new MyThread();Thread t5 = new MyThread();/將線程放入池中進(jìn)行執(zhí)行pool.execute(t1);p
5、ool.execute(t2);pool.execute(t3);pool.execute(t4);pool.execute(t5);/關(guān)閉線程池pool.shutdown();輸入結(jié)果:5pool-1-thread-2正在執(zhí)行pool-1-thread-4正在執(zhí)行pool-1-thread-3正在執(zhí)行pool-1-thread-1正在執(zhí)行pool-1-thread-5正在執(zhí)行4 :ScheduledThreadPoolExecutor14ScheduledExecutorService pool = Executors.newScheduledThreadPool(2);pool.sched
6、uleAtFixedRate(new Runnable() /每隔一段時間就觸發(fā)異常 Override public void run() /throw new RuntimeException(); System.out.println(=); , 1000, 2000, TimeUnit.MILLISECONDS);pool.scheduleAtFixedRate(new Runnable() /每隔一段時間打印系統(tǒng)時間,證明兩者是互不影響的 Override public void run() System.out.println(+); , 1000, 2000, TimeUnit.MILLISECONDS)
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 三農(nóng)產(chǎn)品網(wǎng)絡(luò)營銷作業(yè)指導(dǎo)書
- 2025年懷化考從業(yè)資格證貨運試題
- 小學(xué)二年級數(shù)學(xué)上冊口算題
- 2025年武威貨運上崗證模擬考試試題
- 2025年楚雄駕??荚囏涍\從業(yè)資格證模擬考試
- 電力調(diào)試合同(2篇)
- 電動車補充協(xié)議書范文(2篇)
- 2024-2025學(xué)年高中語文課時作業(yè)4毛澤東詞兩首含解析粵教版必修2
- 六年級班主任第二學(xué)期工作總結(jié)
- 小學(xué)班主任工作計劃二年級
- 2024年安徽省高校分類對口招生考試數(shù)學(xué)試卷真題
- ISO45001管理體系培訓(xùn)課件
- 動畫課件教學(xué)教學(xué)課件
- 會所股東合作協(xié)議書范文范本
- 綿陽市高中2022級(2025屆)高三第一次診斷性考試(一診)數(shù)學(xué)試卷(含答案逐題解析)
- 人教版(2024)七年級上冊英語期中復(fù)習(xí)單項選擇100題(含答案)
- 2024年胡麻油市場前景分析:全球胡麻油市場規(guī)模達(dá)到了25.55億美元
- 小學(xué)英語800詞分類(默寫用)
- 《 西門塔爾牛臉數(shù)據(jù)集的研究》范文
- 八年級上冊 第三單元 11《簡愛》公開課一等獎創(chuàng)新教學(xué)設(shè)計
- 真實世界研究指南 2018
評論
0/150
提交評論