多线程06.thread守护线程
package chapter2; public class Demo02 { public static void main(String[] args) { Thread th1=new Thread(){ @Override public void run() { //主线程 Thread th2=new Thread(){ //守护线程 @Override public void run() { try { Thread.sleep(1_000); System.out.println("T thread finish done."); } catch (InterruptedException e) { e.printStackTrace(); } } }; // 当th1.setDaemon(true),即t为Daemon线程时,主线程结束,守护线程也结束 th2.setDaemon(true); th2.start(); try { while (true) { System.out.println("Do some thing for health check."); Thread.sleep(1_000); } } catch (InterruptedException e) { e.printStackTrace(); } } }; th1.start(); } }
---------------------------------------------------------------------------
国之殇,未敢忘!
南京大屠杀!
731部队!
(有关书籍《恶魔的饱食》)以及核污染水排海等一系列全无人性的操作,购买他们的食品和为它们提供帮助只会更加变本加厉的害你,呼吁大家不要购买日本相关产品
昭昭前事,惕惕后人
吾辈当自强,方使国不受他人之侮!
---------------------------------------------------------------------------
作者:三号小玩家
出处:https://www.cnblogs.com/q1359720840/
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。 版权信息

浙公网安备 33010602011771号