Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.exit in Java Thread

My main thread created a new thread And when the new thread call System.exit(-1),my main thread be closed. How can I handle the exit code and keep the main thread alive?

PS. the new thread will call some method in other .jar file, so I can't modify it.

like image 509
Dozer Avatar asked Apr 11 '13 09:04

Dozer


1 Answers

You can't.

Terminates the currently running Java Virtual Machine. The argument serves as a status code; by convention, a nonzero status code indicates abnormal termination.

That's the javadoc.

So the method will terminate the entire JVM. Not just the thread....

like image 137
Thihara Avatar answered Oct 14 '22 09:10

Thihara