黄色网址大全免费-黄色网址你懂得-黄色网址你懂的-黄色网址有那些-免费超爽视频-免费大片黄国产在线观看

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

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

更新時間:2022-11-16 09:50:01 來源:動力節(jié)點 瀏覽1887次

此示例顯示了一個 Java™ 程序啟動多個線程,等待它們完成,并在完成后檢查它們的狀態(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);
      }
   } 
}          

 

提交申請后,顧問老師會電話與您溝通安排學(xué)習(xí)

免費課程推薦 >>
技術(shù)文檔推薦 >>
主站蜘蛛池模板: 日韩在线第二页 | 免费看片aⅴ免费大片 | 三级福利| 日韩视频中文字幕 | 欧美日韩中文字幕一区二区高清 | 麻豆视频国产 | 欧美国产成人精品一区二区三区 | 亚洲色图综合在线 | 91短视频社区在线观看 | 欧美日韩一区二区三区在线视频 | 亚洲国产成人成上人色 | 精品国语国产在线对白 | 午夜性a一级毛片 | 日韩第3页 | 欧美日韩在线成人 | 黄色男女视频 | 日朝欧美亚洲精品 | 亚洲已满18点击进入在线观看 | 成人在线一区二区三区 | 997在线观看视频国产 | 欧美一区日韩一区中文字幕页 | 久久剧场 | 国产麻豆精品免费视频 | 最近2019中文字幕高清字幕 | 人人做人人做人人爱 | 国产一级αv片免费观看 | 香蕉黄网 | 99热99re8国产在线播放 | 天天干天天添 | 国产成人刺激视频在线观看 | 男无遮挡吃奶gift动态图 | 一级黄色大片免费看 | 最新国产成人综合在线观看 | 看全色黄大色黄女片18 | www夜夜操com| 欧美三级又粗又硬 | 免费成人激情视频 | 欧美成人免费观看 | 日本人亚洲人成人 | 亚洲欧美在线精品一区二区 | 日本国产片 |