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

  2. public class Main {

  3.         public static void main(String[] args) {
  4.                 Thread_0 tt = new Thread_0();
  5.         Thread_1 tt_2 = new Thread_1();
  6.                 tt.start();
  7.                 tt_2.start();
  8.         }

  9. }
複製代碼
  1. package bbs.istak.org.tw;

  2. public class Thread_0 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.                    } catch (InterruptedException e) {}
  11.              }
  12.            System.out.println("時間到!"+Thread.currentThread().getName());
  13.    }
  14. }
複製代碼
  1. package bbs.istak.org.tw;

  2. public class Thread_1 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.                            } catch (InterruptedException e) {}
  11.                      }
  12.                    System.out.println("時間到!"+Thread.currentThread().getName());
  13.            }
  14. }
複製代碼

TOP

返回列表