验证中...
setDaemon(), 设置一个线程为守护线程, 该线程不会单独执行, 当其他非守护线程都执行结束后, 自动退出 
原始数据 复制代码
Thread t1 = new Thread() {
public void run() {
for(int i = 0; i < 2; i++) {
System.out.println(getName() + "...aaaaaaaaaaaaaaaa");
}
}
};
Thread t2 = new Thread() {
public void run() {
for(int i = 0; i < 10; i++) {
System.out.println(getName() + "...bb");
}
}
};
t2.setDaemon(true); //设置为守护线程
t1.start();
t2.start();
Thread-0...aaaaaaaaaaaaaaaa
Thread-0...aaaaaaaaaaaaaaaa
Thread-1...bb
Thread-1...bb
Thread-1...bb
Thread-1...bb
Thread-1...bb
Thread-1...bb
Thread-1...bb
Thread-1...bb
Thread-1...bb
Thread-1...bb
Thread-1...bb
Thread-1...bb
Thread-1...bb
Thread-1...bb

评论列表( 0 )

你可以在登录后,发表评论

搜索帮助