A bug occurred when running a program today, that is, a sub-thread task executed by the main function was launched before it was completed. However, after adding sleep() to the main program, the sub-thread will execute normally and be launched (but it will not work if the sleep time is too short). The debug sub-thread is mainly stuck on the line of code that performs database operations (maybe because it is more time-consuming, and the main thread has no time to wait for you to finish...).
##
Check whether your child thread is set
setDaemon(true)
, Jvm will exit in the following situations:When all running threads are daemon threads
or when no non-daemon thread is running
There is no parent-child relationship between threads. If you need to wait, you can consider the
join()
method. Reference:/a/11...