- package bbs.istak.org.tw;
- public class Main {
- public static void main(String[] args) {
- new myThread1().start();
- new myThread2().start();
- }
- }
- class myThread1 extends Thread
- {
- public void run()
- {
- for( int i=5; i>=1; i--)
- {
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- }
-
- System.out.println(i+"秒"+Thread.currentThread().getName());
- }
- System.out.println("Time Out!!!");
- System.out.println("執行緒名稱:"+Thread.currentThread().getName());
- }
- }
- class myThread2 extends Thread
- {
- public void run()
- {
- for( int i=5; i>=1; i--)
- {
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- }
-
- System.out.println(i+"秒"
- +Thread.currentThread().getName());
- }
- System.out.println("Time Out!!!");
- System.out.println("執行緒名稱:"+Thread.currentThread().getName());
- }
- }
複製代碼 |