Thread interrupts: The flag flag can be used to make the while loop interrupt.
Daemon Thread:
1 2 /*3 daemon Thread, if a process is left with only a daemon thread, the daemon will end4 That means the main thread is gone, and the daemon ends.5 determine if it is a daemon thread: Isdaemon ()6 7 */8 9 @OverrideTen Public voidrun () { One for(inti = 0; I <= 100; i++) { ASYSTEM.OUT.PRINTLN ("Update downloaded" +i+ "%"); - if(i== 100){ -SYSTEM.OUT.PRINTLN ("Update package download complete, ready to install"); the } - Try { -Thread.Sleep (100); -}Catch(interruptedexception e) { + //TODO auto-generated Catch block - e.printstacktrace (); + } A } at } - - Public Static voidMain (string[] args) { - -Demo12 de =NewDemo12 (); - inDe.setdaemon (true);//Set as daemon thread - System.out.println (De.isdaemon ()); to De.start (); + for(inti = 0; I < 100; i++) { -System.out.println (Thread.CurrentThread (). GetName () +i); the } *}
Daemon thread (software update)