?? daemonthreaddemo.java
字號:
class 精靈線程 extends Thread{
public 精靈線程(){
super("精靈線程");
setDaemon(true);
}
public void run(){
System.out.println("精靈線程開始運(yùn)行");
int i = 0;
try{
while(true){
i ++;
Thread.sleep(1000);
System.out.println("精靈線程休息了"+ i + "秒");
}
}catch(Exception e){
System.out.println("Sleep被打斷,出現(xiàn)異常");
}finally{
System.out.println("精靈線程退出");
}
}
}
public class DaemonThreadDemo{
public static void main(String arg[]) throws Exception {
new 精靈線程 ().start();
System.out.println("主線程休息5秒");
new Thread(new Runnable(){
public void run(){
try{Thread.sleep(1000*20);}catch(Exception e){}
}
}).start();
System.out.println("主線程運(yùn)行完畢");
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -