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

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

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

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

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

 

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

免費課程推薦 >>
技術文檔推薦 >>
主站蜘蛛池模板: 日本三级成人午夜视频网 | free性日本| 中文字幕亚洲精品日韩精品 | h片免费观看 | 第一页综合 | 亚洲日本欧美 | 国产亚洲精品一品区99热 | 97在线免费看视频 | 伦理片免费看 | 999成人网| 在线观看日韩视频 | 91在线精品麻豆欧美在线 | 国产丝袜护土调教在线视频 | 伊人久久中文 | 日韩三级大片 | 色天天综合久久久久综合片 | 精品国产日韩亚洲一区在线 | 国产精品自产拍视频观看 | 久久久久亚洲日日精品 | 国产成人aaa在线视频免费观看 | 日比视频在线观看 | 亚洲日韩中文第一精品 | a亚洲天堂| 77ee成人| 欧美性video精品 | 一级特黄特色的免费大片视频 | 国产不卡一区二区视频免费 | 皮皮在线精品亚洲 | 在线观看视频免费 | pornh日本xxxxhd| 午夜96影视 | 99re视频在线播放 | 日本a级片网站 | 小优视频在线观看网 | 欧美高清欧美videosex | 黄色一级视频免费看 | 一级毛片免费全部播放 | 亚洲精品123区 | 日日摸夜夜添夜夜添aa | 欧美高清在线精品一区 | 丁香色综合 |