java多线程快速入门(七)
什么是守护线程
守护线程是为用户线程服务的这么一个线程,主线程结束,守护线程也结束
package com.cppdy; class MyThread3 extends Thread{ @Override public void run() { System.out.println("开始执行线程"); try { sleep(1000); } catch (Exception e) { } System.out.println("结束执行线程"); } } public class ThreadDemo3 { public static void main(String[] args) throws Exception{ MyThread3 mt = new MyThread3(); //设置守护线程 mt.setDaemon(true); mt.start(); Thread.sleep(500); } }