返回列表 發帖
  1. package bbs.istak.org.tw;

  2. public class Main {

  3.         public static void main(String[] args) {
  4.                 new myThread1().start();
  5.                 new myThread2().start();
  6.         }
  7. }

  8. class myThread1 extends Thread
  9. {
  10.         public void run()
  11.         {
  12.                 for( int i=5; i>=1; i--)
  13.                 {
  14.                         try {
  15.                                 Thread.sleep(1000);
  16.                         } catch (InterruptedException e) {
  17.                         }
  18.                        
  19.                         System.out.println(i+"秒"+Thread.currentThread().getName());
  20.                 }
  21.                 System.out.println("Time Out!!!");
  22.                 System.out.println("執行緒名稱:"+Thread.currentThread().getName());

  23.         }
  24.         }

  25. class myThread2 extends Thread
  26. {
  27.         public void run()
  28.         {
  29.                 for( int i=5; i>=1; i--)
  30.                 {
  31.                         try {
  32.                                 Thread.sleep(1000);
  33.                         } catch (InterruptedException e) {
  34.                         }
  35.                        
  36.                         System.out.println(i+"秒"
  37.                                         +Thread.currentThread().getName());
  38.                 }
  39.                 System.out.println("Time Out!!!");
  40.                 System.out.println("執行緒名稱:"+Thread.currentThread().getName());

  41.         }
  42.         }
複製代碼

TOP

返回列表