Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Java exit code without exiting yet

In a highly concurrent program with lots of shutdown operations, wondering how to set the exit code without prematurely calling System.exit()? Possible to set an "execute this code when everything else is done" method? but I'd really just like to prematurely set the exit code.

like image 388
djechlin Avatar asked Sep 07 '12 20:09

djechlin


2 Answers

If I understand correctly what you want is to somehow keep the exit code, run some methods and then call System.exit with the pre-decided exit code.
IMO what you should do is use Shutdown hooks instead. I.e. your code will run before the JVM shuts down and (if I got your requirement correctly) will have the same result with a straightforward coding implementation (i.e. instead of using using state variable and unusual coding logic to achieve what you are trying to do etc)

like image 156
Cratylus Avatar answered Oct 07 '22 01:10

Cratylus


Have a master thread spawn off all other threads such that it only shuts down when all other threads are complete.

like image 29
Guido Anselmi Avatar answered Oct 07 '22 00:10

Guido Anselmi