About Join Method: Join method must be after start, that is, first thread ready, then join, otherwise invalid. Note that the Join method simply allows two threads to execute synchronously, still two threads, not merged into one.
Java Daemon Threads
1, what is the daemon thread (daemon thread).
The daemon thread is a background-running thread, in contrast to the user thread (the users thread). It belongs to the thread that created it, so when the thread that created the guard ends, the daemon dies. (The daemon, if it has its own extinction logic, can die before the daemon) when the running thread is a daemon, the Java virtual machine exits
2, how to create a daemon thread.
Creates a new thread, using the Setdaemon (Boolean on) method to easily set the daemon mode of the thread, true to daemon mode, and false to user mode. the Setdaemon (Boolean on) method must be invoked before the thread is started (that is, before start ()), and an exception is generated when the threads are running. The Isdaemon method tests whether the thread is a daemon thread. It is worth mentioning that when you generate other threads in a daemon, the newly generated threads will be the daemon (and guardian of the same user thread) without setting the Daemon property, as are the user threads.
3, the use of the Guardian thread.
The daemon thread uses less, but is not useless, for example, the JVM's garbage collection, memory management, and other threads are daemon threads. There is in doing database application, the use of the database connection pool, the connection pool itself also contains a lot of background threads, monitoring the number of connections, timeout time, state and so on.
The daemon thread is typically serviced for user threads.
4, the difference between the daemon thread and the user thread.
The user thread has its own lifecycle and does not depend on the thread that created it. The user thread can continue to run after the thread that created it has ended. Threads that run for a limited period of time are typically user threads.
The daemon dies at the end of the created thread. Threads that run indefinitely should usually be defined as daemons, just because you need a way to end them.