返回列表 發帖
  1. public class Ch100
  2. {
  3.         private MyThread1 th1;
  4.         private MyThread2 th2;
  5.        
  6.         Ch100()
  7.         {
  8.                 th1=new MyThread1();
  9.                 th1.start();
  10.                 th2=new MyThread2();
  11.                 th2.start();
  12.                
  13.         }
  14.         public static void main(String[] args)
  15.         {
  16.                 new Ch100();
  17.         }
  18. }       

  19. class MyThread1 extends Thread
  20. {
  21.       public void run() {
  22.                 for(int i=5;i>=1;i--)
  23.                 {
  24.                         System.out.println(i+"秒");
  25.                         try{
  26.                                 Thread.sleep(1000);
  27.                         }catch(InterruptedException e) {}
  28.                 }
  29.            System.out.println("時間到");
  30.            System.out.println("執行緒名稱:"+Thread.currentThread().getName());
  31.         }
  32. }
  33.       class MyThread2 extends Thread
  34.       {
  35.             public void run() {
  36.                       for(int i=5;i>=1;i--)
  37.                       {
  38.                               System.out.println(i+"秒");
  39.                               try{
  40.                                       Thread.sleep(1000);
  41.                               }catch(InterruptedException e) {}
  42.                       }
  43.                  System.out.println("時間到");
  44.                  System.out.println("執行緒名稱:"+Thread.currentThread().getName());
  45.               }
  46.       }
  47.              
複製代碼

TOP

返回列表