返回列表 發帖
  1. package qwer;

  2. public class Qwer {

  3.         public static void main(String[] args) throws InterruptedException
  4.         {                        
  5.                 Thread1 a = new Thread1();
  6.                 Thread2 a2 = new Thread2();
  7.                 a.start();
  8.                 a2.start();
  9.         }
  10. }
複製代碼
  1. package qwer;

  2. public class Thread1 extends Thread {
  3.          public void run()
  4.          {
  5.               for(int i=5 ; i>=1 ; i--)
  6.           {
  7.                 System.out.println(i+"秒"+Thread.currentThread().getName());
  8.                 try {
  9.                         Thread.sleep(1000);
  10.                 }
  11.                 catch (InterruptedException e) {
  12.                          // TODO 自動產生的 catch 區塊
  13.                          e.printStackTrace();
  14.                 }
  15.           }
  16.               System.out.println("時間到!"+Thread.currentThread().getName());
  17.          }
  18. }
複製代碼
  1. package qwer;

  2. public class Thread2 extends Thread {
  3.          public void run()
  4.          {
  5.               for(int i=1 ; i<=5 ; i++)
  6.           {
  7.                 System.out.println(i+"秒"+Thread.currentThread().getName());
  8.                 try {
  9.                         Thread.sleep(1000);
  10.                 }
  11.                 catch (InterruptedException e) {
  12.                          // TODO 自動產生的 catch 區塊
  13.                          e.printStackTrace();
  14.                 }
  15.           }
  16.               System.out.println("時間到!"+Thread.currentThread().getName());
  17.          }
  18. }
複製代碼
我是眾神之王XXX  I love you
0000000000

TOP

返回列表