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

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

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

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

此示例顯示了一個 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);
      }
   } 
}          

 

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

免費課程推薦 >>
技術文檔推薦 >>
主站蜘蛛池模板: 96精品国产高清在线看入口 | 中文字幕第5页 | 色妞色综合久久夜夜 | 国产一级一国产一级毛片 | 青草青青在线视频观看 | 5060一级毛片| 日本3p视频在线看高清 | 老子影院午夜理伦手机不卡 | 男人天堂欧美 | 亚洲自拍中文 | 综合久久久久久 | 欧美性猛交xxxxx按摩欧美 | 久久免费小视频 | 亚洲欧美一区二区三区国产精品 | 国产精品成人在线播放 | 国产原创麻豆精品视频 | 欧洲97色综合成人网 | 成人国产一区二区三区精品 | 欧美性色xo影院在线观看 | freexxxx性特大另类ww | 美女a毛片| 在线观看香蕉免费啪在线观看 | 久久九九热 | 色婷五月 | 久久久综合网 | 在线视频精品一区 | 福利视频一区二区 | 99re在线这里只有精品 | 五月婷婷免费视频 | 日韩高清成人 | 国产精品成人69xxx免费视频 | 久草视频免费在线看 | 国产欧美亚洲精品综合在线 | 一个色综合亚洲色综合 | 一级做a毛片免费视频 | 日韩欧美亚洲每的更新在线 | 中文日韩| 久久久免费观成人影院 | 四虎永久免费884hutv | 久草香蕉视频在线观看 | 99久久免费精品高清特色大片 |