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

java語(yǔ)言

java線程池框架解析方法

時(shí)間:2025-05-04 15:06:56 java語(yǔ)言 我要投稿
  • 相關(guān)推薦

java線程池框架解析方法

  Java對(duì)象實(shí)例的鎖一共有四種狀態(tài):無(wú)鎖,偏向鎖,輕量鎖和重量鎖。原始脫離框架的并發(fā)應(yīng)用大部分都需要手動(dòng)完成加鎖釋放,最直接的就是使用synchronized和volatile關(guān)鍵字對(duì)某個(gè)對(duì)象或者代碼塊加鎖從而限制每次訪問(wèn)的次數(shù),從對(duì)象之間的競(jìng)爭(zhēng)也可以實(shí)現(xiàn)到對(duì)象之間的協(xié)作。但是這樣手動(dòng)實(shí)現(xiàn)出來(lái)的應(yīng)用不僅耗費(fèi)時(shí)間而且性能表現(xiàn)往往又有待提升。

  一、線程池結(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)

【java線程池框架解析方法】相關(guān)文章:

java線程池框架解析09-11

什么是java線程池框架10-02

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

Java 5線程池使用07-28

Java線程同步的方法05-27

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

JAVA多線程之線程間的通信方式解析07-14

Java多線程通信方法09-03

Java實(shí)現(xiàn)多線程的方法11-10

主站蜘蛛池模板: 石景山区| 甘孜县| 灵台县| 黔西| 蚌埠市| 平罗县| 资中县| 和静县| 灌阳县| 玛多县| 宣城市| 汪清县| 贺州市| 上高县| 神池县| 沅江市| 孟村| 巫溪县| 图们市| 东兴市| 宁强县| 夏河县| 达孜县| 蒙阴县| 万荣县| 鸡东县| 清丰县| 乐平市| 囊谦县| 龙井市| 辉县市| 新沂市| 信丰县| 澄江县| 天长市| 通榆县| 杭锦后旗| 齐齐哈尔市| 从江县| 平远县| 涿鹿县|