Http://www.cnblogs.com/super-d2/p/3348183.html has two types of threads in Java: user thread (user threads) , Daemon The thread (daemon)
Daemon is useful for the operation of other threads, such as GC threads. In fact, the user thread thread and the daemon thread daemon are essentially the same, the only difference is in the virtual machine's departure: If the user thread is all evacuated, then daemon thread is not a good service, So the virtual machine is out. The daemon thread is not available inside the virtual machine, and the user can set the daemon on its own, method: public final void Setdaemon (Boolean on); but there are a few caveats: Thread.setdaemon (True) Must be set before Thread.Start (), otherwise a illegalthreadstateexception exception will run out. You cannot set a running general thread as a daemon . (Note: This is clearly different from the daemon, daemon is created, let process get rid of the control of the original session + let the process get rid of the control of the original process group + let the process get rid of the control of the original control terminal; So the language mechanism of the virtual machine is different from the system-level language. The new thread that is generated in the daemon thread is also the daemon . (This is another essential distinction: the Daemon fork () is no longer a daemon, although it replicates the process-related information of the parent process, but the parent process of the subprocess process is not the INIT process, and the so-called daemon is essentially "the parent process hangs, the Init adopts, Then file 0,1,2 are/dev/null, current directory to/"Not all applications can be assigned to daemon threads for service, such as read-write operations or computational logic . The virtual machine may have exited since daemon thread has not yet come in and is operating. The standard for the JRE to determine whether a program is finished is to have all front line Cheng completed, regardless of the background thread's state, so be sure to pay attention to this problem when using background threads.
But the actual application of daemon thread is there. For example, the servlet in the Web server, when the container is started, initializes a service thread, the dispatch thread, which handles the HTTP request, and then each request comes up to dispatch the thread to take a worker thread out of the thread pool to process the request to achieve concurrent control.