- package bbs.istak.org.tw;
- public class Main {
- public static void main(String[] args) {
- T1();
- T2();
- }
- public static void T1()
- {
- Thread t = new Thread()
- {
- public void run()
- {
- for(int i=5; i>=1; i--)
- {
- System.out.println(i+"秒 "+Thread.currentThread().getName());
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- // TODO 自動產生的 catch 區塊
- e.printStackTrace();
- }
- }
- System.out.println("時間到! "+Thread.currentThread().getName());
- }
- };
- t.start();
- }
- public static void T2()
- {
- Thread t = new Thread()
- {
- public void run()
- {
- for(int i=1; i<=5; i++)
- {
- System.out.println(i+"秒 "+Thread.currentThread().getName());
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- // TODO 自動產生的 catch 區塊
- e.printStackTrace();
- }
- }
- System.out.println("時間到! "+Thread.currentThread().getName());
- }
- };
- t.start();
- }
- }
複製代碼 |