Java - Daemon Thread and Restarting a Thread


Daemon Thread

In java there is two type of Threads : Daemon Thread and User Threads. By default, Java thread are created as User Threads. However, you can use setDaemon method to make the thread to be daemon thread. Daemon thread are service provider threads and JVM will kill the daemon thread if there is no other application thread remains. Daemon threads are useful for Java standalone application but not in applet. As applet is running within another application, the daemon thread will live until the execution end.

Restarting a Thread

In Java 5.0 Doc, it is explicitly state that when a thread complete an execution, it cannot be restart. It will thrown IllegalStateException if you try to start the thread again. The best way is to create a new thread to perform your new execution

Below form Javadoc

It is never legal to start a thread more than once. In particular, a thread may not be restarted once it has completed execution.

Comments

Popular Posts