守护线程(daemon)
线程分守护线程和用户线程
虚拟机必须确保用户线程执行完毕
不用等待守护线程执行完毕
如:后台记录操作日志,监控内存,垃圾回收等待+
package Demo4;
//守护线程
public class Test11 {
private static Object God;
public static void main(String[] args) {
God god = new God();
You you = new You();
Thread thread = new Thread(god);
thread.setDaemon(true);//设置为守护线程
thread.start();//启动守护线程
Thread thread1 = new Thread(you);
thread1.start();//启动用户线程
}
}
class You implements Runnable{
@Override
public void run() {
for (int i = 0; i <= 36500; i++) {
System.out.println("这是我活得第"