- package bbs.istak.org.tw;
- public class Main {
- public static void main(String[] args) {
- Thread_0 tt = new Thread_0();
- Thread_1 tt_2 = new Thread_1();
- tt.start();
- tt_2.start();
- }
- }
複製代碼- package bbs.istak.org.tw;
- public class Thread_0 extends 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) {}
- }
- System.out.println("時間到!"+Thread.currentThread().getName());
- }
- }
複製代碼- package bbs.istak.org.tw;
- public class Thread_1 extends 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) {}
- }
- System.out.println("時間到!"+Thread.currentThread().getName());
- }
- }
複製代碼 |