What are the differences between calling System.exit(0) and Thread.currentThread().interrupt() in the main thread of a Java program?

后端 未结 3 1314
深忆病人
深忆病人 2020-12-29 05:54

Both cause a program to stop executing. It\'s clear that there must be some differences in how this happens, though. What are they?

3条回答
  •  误落风尘
    2020-12-29 06:30

    If there are other (non-daemon) threads running, the JVM won't exit if you stop the main thread. System.exit() kills all the other threads.

提交回复
热议问题