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)
留言列表