This commit is contained in:
yinkanglong
2023-10-21 09:48:50 +08:00
parent 5ef2c996cf
commit b2f069ee8d
555 changed files with 1886 additions and 506 deletions

View File

@@ -0,0 +1,45 @@
/**
* 公司:阿里游戏
* 创建时间2018年11月2日下午5:56:43
*/
package cn.aofeng.demo.thread;
import java.util.Date;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* 守护线程DEMO。
*
* @author <a href="mailto:nieyong.ny@alibaba-inc.com">聂勇</a>
*/
public class DaemonThreadDemo extends Thread {
private static Logger logger = LoggerFactory.getLogger(DaemonThreadDemo.class);
@Override
public void run() {
while (true) {
System.out.println("守护线程运行, 时间:" + new Date());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
logger.error("守护线程运行出错", e);
}
}
}
public static void main(String[] args) {
DaemonThreadDemo thread = new DaemonThreadDemo();
thread.setDaemon(true);
thread.start();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
logger.error("主线程运行出错", e);
}
}
}