返回列表 發帖
  1. package tw.kuas.edu.tw;

  2. public class Main {

  3.         public static void main(String[] args) {
  4.                 // TODO 自動產生的方法 Stub
  5.         Thread_0 thread0 = new Thread_0();
  6.         thread0.start();
  7.         Thread_1 thread1 = new Thread_1();
  8.         thread1.start();
  9.         }

  10. }
複製代碼
  1. package tw.kuas.edu.tw;

  2. public class Thread_1 extends Thread{
  3.         public void run()
  4.         {
  5.                 for(int i=1; i<=5; i++)
  6.                 {                       
  7.                         try {
  8.                                 System.out.printf("%d sec at %s \n",i,Thread.currentThread());
  9.                                 Thread.sleep(1000);
  10.                         } catch (InterruptedException e) {
  11.                                 // TODO 自動產生的 catch 區塊
  12.                                 e.printStackTrace();
  13.                         }
  14.                 }
  15.                
  16.         }
複製代碼
  1. package tw.kuas.edu.tw;

  2. public class Thread_0 extends Thread{
  3.         public void run()
  4.         {
  5.                 for(int i=5; i>=0; i--)
  6.                 {
  7.                         try {
  8.                                 System.out.printf("%d sec at %s \n",i,Thread.currentThread());
  9.                                 Thread.sleep(1000);
  10.                         } catch (InterruptedException e) {
  11.                                 // TODO 自動產生的 catch 區塊
  12.                                 e.printStackTrace();
  13.                         }
  14.                 }
  15.                
  16.         }

  17. }
複製代碼

TOP

返回列表