⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e098. allowing an application with live threads to exit.txt

📁 这里面包含了一百多个JAVA源文件
💻 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 + -