I have created a thread which in turn creates a ThreadPoolExecutor
and submits some long running tasks to it. At some point, the original thread dies due to unh
Threads are so called GC roots. This means among other things, that a running (or an unstarted) thread can't be collected. It also means that objects that are being referenced from those threads can't be collected, which is why you can do things like new Thread(new MyRunnable()).start()
, or have threadpools running without you having any reference to them.
If the thread is a daemon, it can stop automatically if all other non-daemon threads have stopped. You can have threadpools with daemon threads, but the best thing is to make sure that things are cleaned up properly (i.e. an exception shouldn't kill the thread that's supposed to eventually stop and cleanup the threadpool).