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

  16. class MyThread extends Thread{
  17.         public void run(){
  18.                 for(int i=5; i>=1; i--){
  19.             System.out.println(i+"秒"+Thread.currentThread().getName());
  20.             try{
  21.                     Thread.sleep(1000);
  22.             }catch(InterruptedException e){}
  23.             }
  24.             System.out.println("時間到");
  25.             System.out.println("執行緒名稱: "+ Thread.currentThread().getName());
  26.         }
  27. }

  28. class MyThread1 extends Thread{
  29.         public void run(){
  30.                 for(int i=5; i>=1; i--){
  31.             System.out.println(i+"秒"+Thread.currentThread().getName());
  32.             try{
  33.                     Thread.sleep(1000);
  34.             }catch(InterruptedException e){}
  35.             }
  36.             System.out.println("時間到");
  37.             System.out.println("執行緒名稱: "+ Thread.currentThread().getName());
  38.         }
  39. }
複製代碼
كخخخخخخخخخخخخخ

TOP

返回列表