[concurrency-interest] Why never daemon threads with defaultthreadfactory?

David Holmes dholmes at dltech.com.au
Wed Sep 7 02:39:36 EDT 2005


> Why are the threads created with the default thread
> factory never deamon threads? even though their threadgroup
> could have the daemon property set to true.

First, daemon threads and daemon threadgroups are completely unrelated.
Daemon threads won't keep the VM alive while they are executing. Daemon
thread groups are automatically destroyed when they become empty.

The default thread factory doesn't create daemon threads because the common
case is that you want any tasks submitted to an executor to actually get
executed. Daemon threads wouldn't support this unless you always used an
application thread to wait until the executor had finished.

If you truly want daemon threads it is easy to change the thread factory.

Note that daemon threads are deceptive creatures. Only the most trivial of
tasks can be arbitrarily terminated in the middle of processing - as would
happen if the JVM terminated.

David Holmes

More information about the Concurrency-interest mailing list