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

📄 e094. determining when a thread has finished.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
This example demonstrates a few ways to determine whether or not a thread has returned from its run() method. 
    // Create and start a thread
    Thread thread = new MyThread();
    thread.start();
    
    // Check if the thread has finished in a non-blocking way
    if (thread.isAlive()) {
        // Thread has not finished
    } else {
        // Finished
    }
    
    // Wait for the thread to finish but don't wait longer than a
    // specified time
    long delayMillis = 5000; // 5 seconds
    try {
        thread.join(delayMillis);
    
        if (thread.isAlive()) {
            // Timeout occurred; thread has not finished
        } else {
            // Finished
        }
    } catch (InterruptedException e) {
        // Thread was interrupted
    }
    
    // Wait indefinitely for the thread to finish
    try {
        thread.join();
        // Finished
    } catch (InterruptedException e) {
        // Thread was interrupted
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -