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

專注Java教育14年 全國咨詢/投訴熱線:400-8080-105
動力節點LOGO圖
始于2009,口口相傳的Java黃埔軍校
首頁 學習攻略 Java學習 使用Java程序來等待線程結束

使用Java程序來等待線程結束

更新時間:2022-11-16 09:50:01 來源:動力節點 瀏覽1893次

此示例顯示了一個 Java™ 程序啟動多個線程,等待它們完成,并在完成后檢查它們的狀態。

/*
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);
      }
   } 
}          

 

提交申請后,顧問老師會電話與您溝通安排學習

免費課程推薦 >>
技術文檔推薦 >>
主站蜘蛛池模板: 欧美在线香蕉在线现视频 | 中文精品北条麻妃中文 | 大学生一级毛片高清版 | 欧美一级毛片香蕉网 | 亚洲在线视频免费观看 | 久久久久久久影院 | 夜夜精品视频一区二区 | 四虎免费在线 | 美女个护士一级毛片亚洲 | 国产一区二区三区日韩欧美 | 国产一级内谢a级高清毛片 国产一级片毛片 | 国产一区亚洲二区 | 国产综合欧美日韩视频一区 | 国产国拍亚洲精品午夜不卡17 | 色婷婷久久 | chinese国产人妖视频网站 | 久久免费精品视频在线观看 | 一级毛片a女人刺激视频免费 | 一级特黄特黄的大片免费 | 日本一级毛片高清免费观看视频 | 中文字幕日韩视频 | 精品国产自在久久 | 99视频精品全部免费免费观 | 久久频这里精品99香蕉久 | 波多野结衣亚洲一区二区三区 | 四虎永久在线观看视频精品 | 97在线看| 男人天堂网在线观看 | 国产亚洲综合一区在线 | 日韩欧美第一区二区三区 | 国内精品欧美久久精品 | 日本a在线观看 | 九色综合网 | 亚欧精品在线观看 | 亚洲一二三 | 亚洲国产精品一区二区三区 | 伦理亚洲 | 天天天操天天天干 | 何以笙箫默在线观看 | 国产综合区 | 色婷婷久久综合中文久久一本` |