返回列表 發帖
  1. public class Ch124 {
  2.     private MyThread1 th1;
  3.     private MyThread2 th2;
  4.     Ch124()
  5.     {
  6.             th1=new MyThread1();
  7.             th1.start();
  8.         th2=new MyThread2();
  9.             th2.start();
  10.         }
  11.         public static void main(String[] args) {
  12.             new Ch124();
  13.         }
  14. }
  15. class MyThread1 extends Thread
  16. {
  17.         public void run()
  18.         {
  19.                 for(int i=5;i>=1;i--)
  20.         {
  21.                 System.out.println(i+"秒"+Thread.currentThread().getName());
  22.                 try {
  23.                         Thread.sleep(1000);
  24.                 } catch (InterruptedException e) {}        
  25.         }
  26.         System.out.println("時間到");
  27.         System.out.println("執行緒名稱:"+Thread.currentThread().getName());
  28.         }
  29. }
  30. class MyThread2 extends Thread
  31. {
  32.         public void run()
  33.         {
  34.                 for(int i=5;i>=1;i--)
  35.         {
  36.                 System.out.println(i+"秒"+Thread.currentThread().getName());
  37.                 try {
  38.                         Thread.sleep(1000);
  39.                 } catch (InterruptedException e) {}        
  40.         }
  41.         System.out.println("時間到");
  42.         System.out.println("執行緒名稱:"+Thread.currentThread().getName());
  43.         }
  44. }
複製代碼

TOP

返回列表