Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it bad for a java application to shutdown while a separate thread is sleeping?

For example if i have a java command line program that spawns a new thread (thread #2) to do some polling, and then sleep for 5 minutes. while the main thread (thread #1) of the program is running and then finishes before the 5 minutes from thread #2 is up, so the program will exit. Is there any problem with this? Should I interrupt Thread #2 in Thread #1 before the end of the main function in this program?

like image 386
czer Avatar asked Nov 06 '22 03:11

czer


1 Answers

It may be considered bad practice and a sign of poor design by some, but in principal there shouldn't be any problem to terminate the JVM with System.exit. Not if there is no clean-up to be performed by Thread #2.

Another issue though, is whether or not Thread #2 may be in the middle of some action.

like image 137
aioobe Avatar answered Nov 09 '22 12:11

aioobe