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

后端 未结 3 1296
深忆病人
深忆病人 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:13

    In a multithreaded application, there are more than one thread executing . Thread.currentThread().interrupt() only interrupts your current executing thread, but the remaining thread will be running, even if your main thread is interrupted..

    Whereas, System.exit(0) results your system to be ended.. And all the threads are killed..

提交回复
热议问题