守护线程
2021-04-12 00:27
标签:exception 退出 for try static ace 代码 方法 其它 守护线程 标签:exception 退出 for try static ace 代码 方法 其它 原文地址:https://www.cnblogs.com/realzhaijiayu/p/13358183.htmlThread t = new Thread();
t.setDaemon(true);
t.start();
package com.zhaijiayu;
public class Main {
public static void main(String[] args) throws InterruptedException {
Thread t = new Thread1();
// t.setDaemon(true);//设置为守护线程
t.start();
System.out.println("main: wait 3 sec...");
try{
Thread.sleep(3000);
}catch (InterruptedException e){
}
System.out.println("end");
}
}
class Thread1 extends Thread{
@Override
public void run() {
for(;;){
System.out.println("Thread-1: running...");
try{
Thread.sleep(500);
}catch (InterruptedException e){
break;
}
}
}
}
下一篇:5.0 python基本数据类型