daemon(守护、服务员)
t1.setDaemon(true) - 设置为守护线程

class KTV extends Thread{
public void run(){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName()+" - 消费结束");
}
}
class Waiter extends Thread{
public void run(){
while(true){
try {
Thread.sleep(300);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("随时服务 - "+new java.util.Date());
}
}
}
public class Demo14 {
public static void main(String[] args) {
KTV k1=new KTV();
KTV k2=new KTV();
Waiter w1=new Waiter();
w1.setDaemon(true); //设置为守护线程 k1.start();
k2.start();
w1.start();
}
}

  daemon(守护、服务员)-t1.setDaemon(true) - 设置为守护线程-LMLPHP

05-12 20:49