- package tw.kuas.edu.tw;
- public class Main {
- public static void main(String[] args) {
- // TODO 自動產生的方法 Stub
- Thread_0 thread0 = new Thread_0();
- thread0.start();
- Thread_1 thread1 = new Thread_1();
- thread1.start();
- }
- }
複製代碼- package tw.kuas.edu.tw;
- public class Thread_1 extends Thread{
- public void run()
- {
- for(int i=1; i<=5; i++)
- {
- try {
- System.out.printf("%d sec at %s \n",i,Thread.currentThread());
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- // TODO 自動產生的 catch 區塊
- e.printStackTrace();
- }
- }
-
- }
複製代碼- package tw.kuas.edu.tw;
- public class Thread_0 extends Thread{
- public void run()
- {
- for(int i=5; i>=0; i--)
- {
- try {
- System.out.printf("%d sec at %s \n",i,Thread.currentThread());
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- // TODO 自動產生的 catch 區塊
- e.printStackTrace();
- }
- }
-
- }
- }
複製代碼 |