记一个疑惑--一个进程中的两个线程,有一个线程挂了,另外一个线程能正常运行吗?

420 阅读1分钟

如题,今天遇到这个疑惑,于是打开 idea 准备做下试验,代码如下:

    public static void main(String[] args) {
        Solution solution = new Solution();
        
        new Thread(()->{
            System.out.println(1/0);
        }).start();
        new Thread(()->{
            System.out.println("正常运行");
        }).start();
        
    }

运行结果:

Exception in thread "Thread-0" java.lang.ArithmeticException: / by zero
	at Solution.lambda$main$0(Solution.java:16)
	at java.lang.Thread.run(Thread.java:748)
正常运行

也就是说,一个进程中的线程是相互独立的。