If a Thread creates a daemon Thread, can I rely on the fact that when the parent exits the run method, the son will also terminate?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No – threads are independent. There’s no sense of one thread “owning” another and forcing termination.
If you’re really asking whether when all the non-daemon threads in the application have died, you can rely on the process dying: yes, you can. But that’s all you can rely on.
In particular, if there are two non-daemon threads, each of which has created a daemon thread, and one of the non-daemon threads terminates, then the remaining three threads will continue running.