There is a thread that runs in the background, and its task is to provide services to other threads, which are called "Background threads" (Daemon thread), also known as "Daemon threads."
A typical background thread is the timer "timer" thread, which is responsible for sending a fixed interval of time to other threads.
Background threads are often used for aftercare at the end of a task. In addition, background threads have a lower priority than other threads.
A generic thread is called a "user thread" compared to a background thread. If only a background thread is running in an app, the JVM exits the application.
A normal thread can be set as a background thread through Setdaemon (Boolean D). The method Isdaemon () can be used to test whether a particular thread is a background thread.
Package Com.liujl.thread;public class Daemonthread extends thread{ @Override public void Run () {while ( true) { System.out.println ("Daemonthread is running ...");} ; public static void Main (string[] args) { daemonthread dt=new daemonthread (); Dt.setdaemon (true); Dt.start (); } /** * Dt.setdaemon (TRUE), set the DT thread as the daemon thread, then call Start (); * After the DT thread executes for a period of time, it will automatically exit, because the thread dispatcher is monitoring that only * A background thread is running, it terminates the operation of the referencing program. * * The reader can remove the code from line 13th and run the reference again, at which point the application will run indefinitely. */}
Background thread (daemon thread)