PackageCn.itcast.thread;/*daemon Thread (background thread), if only the daemon thread is left in a process, then the daemon thread will die. * The way to define the daemon thread: * Call Thread Setdaemo (true) to set the thread as the daemon thread, the rest of the usage is the same as the normal thread*/ Public classDemo8extendsThread { PublicDemo8 (String name) {Super(name); } @Override Public voidrun () { for(inti = 1; I <= 100; i++) {System.out.println ("Update package Download:" + i + "%" ); Try{Thread.Sleep (200); } Catch(interruptedexception e) {e.printstacktrace (); } if(i = = 100) {System.out.println ("Update package download complete, ready to install ..."); } } } Public Static voidMain (string[] args) {Demo8 d=NewDemo8 ("Background thread"); //To set a thread as a daemon threadD.setdaemon (true); System.out.println (D.isdaemon ()); D.start (); for(inti = 1; I <= 100; i++) {System.out.println (Thread.CurrentThread (). GetName ()+i); Try{Thread.Sleep (100); } Catch(interruptedexception e) {e.printstacktrace (); } } }}
Java thread--daemon thread