📄 daemonthreaddemo.java
字号:
class 精灵线程 extends Thread{
public 精灵线程(){
super("精灵线程");
setDaemon(true);
}
public void run(){
System.out.println("精灵线程开始运行");
int i = 0;
try{
while(true){
i ++;
Thread.sleep(1000);
System.out.println("精灵线程休息了"+ i + "秒");
}
}catch(Exception e){
System.out.println("Sleep被打断,出现异常");
}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("主线程运行完毕");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -