package com.gxx.threads.study.test14; /** * 测试类-测试守护线程 * @author Gxx */ public class Test { /** * main方法 * @param args */ public static void main(String[] args) { System.out.println("[main][非守护线程] 开始"); MyThread thread = new MyThread(); thread.setName("Thead"); System.out.println("[线程][" + thread.getName() + "]默认为" + (thread.isDaemon()?"[true][守护线程]":"[false][非守护线程]")); System.out.println("[线程][" + thread.getName() + "]设置为[true][守护线程]"); thread.setDaemon(true); thread.start(); try { Thread.sleep(10000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("[main][非守护线程] 结束,则[守护线程]也自动结束"); } }