package pkg9.pkg13;

class MyThread implements Runnable{
    public void run(){
        System.out.println("1.進入run方法");
        try{
            Thread.sleep(10000);            //休眠10秒
            System.out.println("2.完成休眠");
        }catch(Exception e){
            System.out.println("3.休眠被終止");
            return;
        }
    }
}
public class Main {

    public static void main(String[] args) {
        MyThread mt  = new MyThread();
        Thread t = new Thread(mt,"Thread - A");
        t.start();
        
        try{
            Thread.sleep(2000);  //休息2秒再繼續中斷
        }catch(Exception e){
        }
        t.interrupt();          //中斷執行緒執行
    }
}
 


run:
1.進入run方法
3.休眠被終止
BUILD SUCCESSFUL (total time: 2 seconds)
 

arrow
arrow
    文章標籤
    Java
    全站熱搜
    創作者介紹
    創作者 mingyilai 的頭像
    mingyilai

    mingyilai的部落格

    mingyilai 發表在 痞客邦 留言(0) 人氣()