- package bbs.istak.org.tw;
- import java.io.IOException;
- public class test {
- public static void main (String[] arg0) throws InterruptedException, IOException{
- tick();
- tok();
-
- }
-
- public static void tick(){
-
-
- Thread t1 = new Thread(){
-
- public void run(){
-
- Thread.currentThread().setName("tick " );
-
- for(int i = 10 ; i > 0 ; i--){
-
- System.out.println(i+"s "+Thread.currentThread().getName());
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- // TODO 自動產生的 catch 區塊
- e.printStackTrace();
- }
-
- }
- System.out.println(Thread.currentThread().getName()+" FINISH");
-
-
- }
- };
- t1.start();
-
- }
-
- public static void tok(){
-
- Thread t2 = new Thread(){
-
- public void run(){
-
- Thread.currentThread().setName("tok ");
-
- for(int i = 10 ; i > 0 ; i--){
-
- System.out.println(i+"s "+Thread.currentThread().getName());
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- // TODO 自動產生的 catch 區塊
- e.printStackTrace();
- }
-
- }
- System.out.println(Thread.currentThread().getName()+" FINISH");
-
-
- }
- };
- t2.start();
- }
- }
複製代碼 |