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

  2. import java.io.IOException;

  3. public class test {

  4.         public static void main (String[] arg0) throws InterruptedException, IOException{
  5.                 tick();
  6.                 tok();
  7.                
  8.         }
  9.        
  10.         public static void tick(){
  11.                
  12.                
  13.                 Thread t1 = new Thread(){
  14.                        
  15.                         public void run(){
  16.                                
  17.                                 Thread.currentThread().setName("tick " );
  18.                                
  19.                         for(int i = 10 ; i > 0 ; i--){
  20.                                
  21.                                 System.out.println(i+"s "+Thread.currentThread().getName());
  22.                                 try {
  23.                                         Thread.sleep(1000);
  24.                                 } catch (InterruptedException e) {
  25.                                         // TODO 自動產生的 catch 區塊
  26.                                         e.printStackTrace();
  27.                                 }
  28.                                
  29.                         }
  30.                         System.out.println(Thread.currentThread().getName()+" FINISH");
  31.                        
  32.                        
  33.                         }
  34.                 };
  35.                 t1.start();
  36.                
  37.         }
  38.        
  39.         public static void tok(){
  40.                
  41. Thread t2 = new Thread(){
  42.                        
  43.                         public void run(){
  44.                                
  45.                                 Thread.currentThread().setName("tok ");
  46.                                
  47.                         for(int i = 10 ; i > 0 ; i--){
  48.                                
  49.                                 System.out.println(i+"s "+Thread.currentThread().getName());
  50.                                 try {
  51.                                         Thread.sleep(1000);
  52.                                 } catch (InterruptedException e) {
  53.                                         // TODO 自動產生的 catch 區塊
  54.                                         e.printStackTrace();
  55.                                 }
  56.                                
  57.                         }
  58.                         System.out.println(Thread.currentThread().getName()+" FINISH");
  59.                        
  60.                        
  61.                         }
  62.                 };
  63.                 t2.start();
  64.         }
  65. }
複製代碼

TOP

返回列表