//守护线程当其他用户线程运行结束,守护线程结束运行,见代码:
package ThreadTest;
class Processor13 implements Runnable{
@Override
public void run() {
// TODO Auto-generated method stub
while(true){
try{
Thread.sleep(1000);
}catch(Exception e){
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName() + " thread is running");
}
}
}
public class ThreadTest13 {
public static void main(String[] args) throws InterruptedException{
Processor13 pro = new Processor13();
Thread t = new Thread(pro, "t");
t.setDaemon(true);
t.start();
for(int i=0; i<10; i++){
Thread.sleep(1000);
System.out.println(Thread.currentThread().getName() + " thread is running");
}
}
}