java - The main thread exits without the child thread ending
typecho
typecho 2017-06-12 09:21:01
0
2
1088

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...).


##

typecho
typecho

Following the voice in heart.

reply all(2)
小葫芦

Check whether your child thread is set setDaemon(true), Jvm will exit in the following situations:

  1. When all running threads are daemon threads

  2. 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...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!