大战熟女丰满人妻av-荡女精品导航-岛国aaaa级午夜福利片-岛国av动作片在线观看-岛国av无码免费无禁网站-岛国大片激情做爰视频

專注Java教育14年 全國(guó)咨詢/投訴熱線:400-8080-105
動(dòng)力節(jié)點(diǎn)LOGO圖
始于2009,口口相傳的Java黃埔軍校
首頁(yè) 學(xué)習(xí)攻略 Java學(xué)習(xí) 使用Java程序來(lái)等待線程結(jié)束

使用Java程序來(lái)等待線程結(jié)束

更新時(shí)間:2022-11-16 09:50:01 來(lái)源:動(dòng)力節(jié)點(diǎn) 瀏覽1951次

此示例顯示了一個(gè) Java™ 程序啟動(dòng)多個(gè)線程,等待它們完成,并在完成后檢查它們的狀態(tài)。

/*
FileName: ATEST15.java 
The output of this example is as follows:
 Entered the testcase
 Create some worker threads
 Start the thread
 Thread Thread-1: Entered
 Thread Thread-1: Working
 Thread Thread-2: Entered
 Thread Thread-2: Working
 Thread Thread-3: Entered
 Thread Thread-3: Working
 Thread Thread-4: Entered
 Thread Thread-4: Working
 Wait for worker threads to complete
 Thread Thread-5: Entered
 Thread Thread-5: Working
 Thread Thread-1: Done with work
 Thread Thread-2: Done with work
 Thread Thread-3: Done with work
 Thread Thread-4: Done with work
 Thread Thread-5: Done with work
 Check all thread's results
 Testcase completed
*/
import java.lang.*; 
public class ATEST15 {
   public final static int THREADGROUPSIZE   = 5; 
   static class theThread extends Thread {
      public final static int THREADPASS     = 0;
      public final static int THREADFAIL     = 1;
      int         _status; 
      public int status() {
         return _status;
      }
      public theThread() {
         _status = THREADFAIL;
      }
      public void run() {
         System.out.print("Thread " + getName() + ": Entered\n");
         System.out.print("Thread " + getName() + ": Working\n");
         safeSleep(15000, "Thread " + getName() + " work");
         System.out.print("Thread " + getName() + ": Done with work\n");
         _status = THREADPASS;
      }
   } 
   public static void main(String argv[]) {
      int           i=0;
      theThread     thread[] = new theThread[THREADGROUPSIZE]; 
      System.out.print("Entered the testcase\n"); 
      System.out.print("Create some worker threads\n");
      System.out.print("Start the thread\n");
      /* We won't use a ThreadGroup for this example, because we'd */
      /* still have to join all the threads individually           */
      for (i=0; i <THREADGROUPSIZE; ++i) {
  thread[i] = new theThread();
         thread[i].start();
      } 
      System.out.print("Wait for worker threads to complete\n");
      for (i=0; i <THREADGROUPSIZE; ++i) {
try {
            thread[i].join();
         }
         catch (InterruptedException e) {
            System.out.print("Join interrupted\n");
         }
      }
      System.out.print("Check all thread's results\n");
      for (i=0; i <THREADGROUPSIZE; ++1) {
if (thread[i].status() != theThread.THREADPASS) {
            System.out.print("Unexpected thread status\n");
         }
      } 
      System.out.print("Testcase completed\n");
      System.exit(0);
   } 
   public static void safeSleep(long milliseconds, String s) {
      try {
         Thread.sleep(milliseconds);
      }
      catch (InterruptedException e) {
         System.out.print(s);
      }
   } 
}          

 

提交申請(qǐng)后,顧問(wèn)老師會(huì)電話與您溝通安排學(xué)習(xí)

  • 全國(guó)校區(qū) 2025-10-10 搶座中
免費(fèi)課程推薦 >>
技術(shù)文檔推薦 >>
主站蜘蛛池模板: 久久精品国产欧美日韩亚洲 | 夜夜夜夜夜夜爽噜噜噜噜噜噜 | 国产ww久久久久久久久久 | 日本福利片国产午夜久久 | 国产一级高清视频 | 波多野结衣一区二区在线 | 国产一级精品毛片 | 在线 | 一区二区三区 | 网友自拍视频悠悠在线 | 午夜在线播放免费高清观看 | 香蕉精品 | 国内精品久久久久丫网址 | 国产成人亚洲综合a∨婷婷 国产成人亚洲综合欧美一部 | 四虎免费播放观看在线视频 | 九九视频免费精品视频免费 | 国产欧美视频在线观看 | 亚洲精品视频在线看 | 中文在线观看视频 | 国产综合成人亚洲区 | 高清黄色直接看 | 国产ww久久久久久久久久 | 99热久久国产这里有只有精品 | 日本深夜影院 | 亚洲人成网站在线观看青青 | 最新国产精品好看的国产精品 | 亚洲成综合 | 亚洲精品国产字幕久久vr | 亚洲精品专区一区二区三区 | 亚洲第一伊人 | 麻豆国内精品欧美在线 | 国产欧美在线观看精品一区二区 | 第四色婷婷基地 | 日本黄色网址视频 | 久久亚洲影院 | 91在线网址 | aaa一级特黄| 久久久久久亚洲精品中文字幕 | 99爱在线精品视频免费观看9 | 免费人成在线观看69式小视频 | 寡妇野外啪啪一区二区 | 欧美日韩在线视频一区 |