📄 e098. allowing an application with live threads to exit.txt
字号:
An application will automatically exit when there are no non-daemon threads running. In other words, a live daemon thread does not prevent an application from exiting.
A thread must be marked as a daemon thread before it is started. It cannot become a daemon thread after it is started. This means that you could not implement, for example, a thread pool where the threads become daemon threads only when inactive.
// This class extends Thread
class MyThread extends Thread {
MyThread() {
// Thread can be set as a daemon thread in the constructor
setDaemon(true);
}
// This method is called when the thread runs
public void run() {
// Determine if this thread is a daemon thread
boolean isDaemon = isDaemon();
}
}
// Create the thread
Thread thread = new MyThread();
// Thread can be set as daemon by the creator
thread.setDaemon(true);
// Start the thread
thread.start();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -