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

  2. public class Main {

  3.         public static void main(String[] args) {
  4.                 T1();
  5.                 T2();
  6.         }
  7.     public static void T1()
  8.     {
  9.             Thread t = new Thread()
  10.             {
  11.                     public void run()
  12.                     {
  13.                             for(int i=5; i>=1; i--)
  14.                             {
  15.                                     System.out.println(i+"秒 "+Thread.currentThread().getName());
  16.                                     try {
  17.                                                 Thread.sleep(1000);
  18.                                         } catch (InterruptedException e) {
  19.                                                 // TODO 自動產生的 catch 區塊
  20.                                                 e.printStackTrace();
  21.                                         }
  22.                             }
  23.                             System.out.println("時間到! "+Thread.currentThread().getName());
  24.                     }
  25.             };
  26.             t.start();
  27.     }
  28.     public static void T2()
  29.     {
  30.             Thread t = new Thread()
  31.             {
  32.                     public void run()
  33.                     {
  34.                             for(int i=1; i<=5; i++)
  35.                             {
  36.                                     System.out.println(i+"秒 "+Thread.currentThread().getName());
  37.                                     try {
  38.                                                 Thread.sleep(1000);
  39.                                         } catch (InterruptedException e) {
  40.                                                 // TODO 自動產生的 catch 區塊
  41.                                                 e.printStackTrace();
  42.                                         }
  43.                             }
  44.                             System.out.println("時間到! "+Thread.currentThread().getName());
  45.                     }
  46.             };
  47.             t.start();
  48.     }
  49. }
複製代碼

TOP

返回列表