linux中死java线程发生了什么?

nah*_*hsh 2 java linux multithreading exception stability

我的项目中有一个NullPointerException,我想评估这个问题的重要性.在线程完成任务并且无论如何都要死之前抛出异常.我的代码没有抓住这个例外,所以线程已经死了.

以下是对情况的简单模拟:

public class Test extends Thread {
    public static void main(String[] args) throws InterruptedException {

        Test thread = new Test();
        thread.start();
        while(true) {
           System.out.println("I'm still here!");
           Thread.sleep(1000);
        }
    }

    public void run() {
        String s = null;
        int len = s.length(); // causes NullPinterException
    }
}
Run Code Online (Sandbox Code Playgroud)

我的问题是:现在这条糟糕的线程会发生什么?它的linux文件描述符是否被释放?在这种代码中是否存在任何稳定性或记忆问题?

Hau*_*idt 5

处理与任何其他终止线程没有区别.一件事情之前发生是寻找一个的UncaughtExceptionHandler根据规则(具体Thread,ThreadGroup,所有线程),但除了这种"正常"清除过程如下.Thread与"正常"终止相比,当线程被未捕获的异常终止时,没有关于系统资源(取决于实现)或内存问题的具体后果.