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

  2. public class Main {

  3.         Main()
  4.         {
  5.                
  6.                 show1();
  7.                 show2();
  8.                
  9.        
  10.                
  11.         }
  12.         void show1()
  13.         {
  14.                 Thread th = new Thread(){
  15.                         public void run()
  16.                         {
  17.                                 for( int i=5; i>=1; i--)
  18.                                 {
  19.                                         try {
  20.                                                 Thread.sleep(1000);
  21.                                         } catch (InterruptedException e) {
  22.                                         }
  23.                                        
  24.                                         System.out.println(i+"秒"+Thread.currentThread().getName());
  25.                                 }
  26.                                 System.out.println("Time Out!!!");
  27.                                 System.out.println("執行緒名稱:"+Thread.currentThread().getName());
  28.         }
  29.                        
  30.         void show2 ()
  31.         {
  32.                 Thread th = new Thread(){
  33.                 public void run()
  34.                 {
  35.                         for( int i=5; i>=1; i--)
  36.                         {
  37.                                 try {
  38.                                         Thread.sleep(1000);
  39.                                 } catch (InterruptedException e) {
  40.                                 }
  41.                                
  42.                                 System.out.println(i+"秒"
  43.                                                 +Thread.currentThread().getName());
  44.                         }
  45.                         System.out.println("Time Out!!!");
  46.                         System.out.println("執行緒名稱:"+Thread.currentThread().getName());

  47.                 }
  48.                 }
  49.                
  50.         ;
  51.         }
  52.        
  53.         public static void main(String[] args) {
  54.                         new Main();
  55.         }
  56. }
複製代碼

TOP

返回列表