Threads of Control |
Any Java thread can be a daemon thread. Daemon threads are service providers for other threads or objects running in the same process as the daemon thread. For example, the HotJava browser has a daemon thread, named Background Image Reader, that reads images from the filesystem or the network for any object or thread that needs an image.Daemon threads are typically independent threads within an application that provide services for other objects within that same application. The
run()
method for a daemon thread is typically an infinite loop that waits for a service request.When the only remaining threads in a process are daemon threads, the interpreter exits. This makes sense because when there are only daemon threads remaining, there is no other thread for which a daemon thread can provide a service.
To specify that a thread is a daemon thread call the
setDaemon()
method with a boolean parameter that is true. To determine if a thread is a daemon thread use the accessor methodisDaemon()
.[PENDING: write an example]
Threads of Control |