In Java, a main thread creates and starts another thread.
If the main thread does not call join()
to wait for the new thread to finish, the new thread will continue running after the main thread exits.
Is there some usage for the main thread not calling join()
?
For comparison to Linux, I learned from APUE that when a program fork()
s a child process and doesn't call waitpid()
to wait for the child process to finish but exits while the child continues to run, we can
re-parent the child to be adopted by
init
process (which can prevent it become a zombie process), andmake the child not a leader of any process group or process session, so that the child can call
setsid()
to disassociate from its controlling terminal (which can make the child a daemon process)
Is it correct that the above two benefits don't apply to the Java threads?
Thanks.