奶头挺立呻吟高潮av全片,成人试看120秒体验区,性欧美极品v,A片高潮抽搐揉捏奶头视频

java語言

什么是java線程池框架

時(shí)間:2025-03-12 11:59:32 java語言 我要投稿

什么是java線程池框架

  多線程是程序員面試時(shí)常常會(huì)面對(duì)的問題,對(duì)多線程概念的掌握和理解水平,也常常被用來衡量一個(gè)人的編程實(shí)力。不錯(cuò),普通的多線程已經(jīng)不容易了。

  一、線程池結(jié)構(gòu)圖

  二、示例

  定義線程接口

  6public class MyThread extends Thread {@Overridepublicvoid run() {System.out.println(Thread.currentThread().getName() + "正在執(zhí)行");}}

  1:newSingleThreadExecutor

  10ExecutorService pool = Executors. newSingleThreadExecutor();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:newFixedThreadPool

  13ExecutorService pool = Executors.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í)行pool-1-thread-2正在執(zhí)行pool-1-thread-1正在執(zhí)行pool-1-thread-2正在執(zhí)行

  3 :newCachedThreadPool

  14ExecutorService 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);pool.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 :ScheduledThreadPoolExecutor

  14ScheduledExecutorService pool = Executors.newScheduledThreadPool(2);pool.scheduleAtFixedRate(new Runnable() {//每隔一段時(shí)間就觸發(fā)異常 @Override public void run() { //throw new RuntimeException(); System.out.println("================"); }}, 1000, 2000, TimeUnit.MILLISECONDS);pool.scheduleAtFixedRate(new Runnable() {//每隔一段時(shí)間打印系統(tǒng)時(shí)間,證明兩者是互不影響的 @Override public void run() { System.out.println("+++++++++++++++++"); }}, 1000, 2000, TimeUnit.MILLISECONDS);

  輸入結(jié)果:

  4================+++++++++++++++++++++++++++++++++++++++++++++++++++

  三、線程池核心參數(shù)

  corePoolSize : 池中核心的線程數(shù)

  maximumPoolSize : 池中允許的最大線程數(shù)。

  keepAliveTime : 當(dāng)線程數(shù)大于核

【什么是java線程池框架】相關(guān)文章:

java線程池框架是什么09-03

java線程池框架解析09-11

java線程池框架解析方法10-13

Java 5線程池使用07-28

java中通用的線程池實(shí)例代碼08-27

什么是java主線程08-13

java主線程是什么05-20

java的多線程09-09

java多線程08-31

主站蜘蛛池模板: 大城县| 晋江市| 崇左市| 新疆| 资溪县| 文成县| 北票市| 西畴县| 夏津县| 阿坝| 阆中市| 文水县| 黎平县| 乳山市| 沂南县| 铁力市| 高碑店市| 关岭| 广东省| 鹤岗市| 隆德县| 竹溪县| 肇源县| 喜德县| 扬中市| 靖州| 巴楚县| 射阳县| 封开县| 台东县| 惠水县| 浏阳市| 集安市| 晋中市| 禄劝| 康乐县| 犍为县| 福清市| 松江区| 改则县| 岱山县|