1, multithreading can be implemented runnable interface or inherited thread, can only be started by the thread class start () method to start a thread 2, there are two types of threads in Java: User thread, Daemon thread (daemon)
It is estimated that the students who have studied UNIX development but have not studied Java in detail will be puzzled that there is no concept of the Guardian thread in the operating system, only the daemon is said, but the Java language mechanism is built on the JVM, which means that the Java platform shields the bottom of the operating system. So it can be in its own virtual platform to construct a favorable mechanism for themselves, and the language or platform of the designer is more or less affected by the Unix idea, and the daemon thread mechanism is the JVM such a platform, so the Guardian thread came into being.
The role of Daemon is to provide services for the operation of other threads, such as GC threads. In fact, the user thread and the daemon thread daemon is essentially no different, 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 also exits.
The daemon thread is not available inside the virtual machine, and the user can set the daemon thread by itself: public final void Setdaemon (Boolean on), but there are a few things to note:
1), Thread.setdaemon (true) must be set before Thread.Start (), or a illegalthreadstateexception exception will run out. You cannot set a running regular thread as a daemon thread. (Note: This is a significant difference from the daemon, the daemon is created, let the process out of the original session control + let the process out of the original Process group Control + Let the process out of the original control terminal control; So the language mechanism pinned to the virtual machine is fundamentally different from the system-level language)
2), the new thread generated in the daemon thread is also daemon.
3. Multi-threaded coordination Help class
Countdownlatch control the parent thread blocks until the multithreaded execution is complete
Cyclicbarrier control multithreading at a certain point in sync
Semaphore control simultaneous execution of threads
Exchanger two threads exchanging data at a point
4, future, Futuretask remote Call does not block
Java Threads-Multithreading-Daemon threads