public static void main(String[] args) {
Thread p1 = new Thread(){
public void run() {
for (int i = 0; i < 10; i++) {
System.out.println("go go go !!! ");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("111111");
};
};
p1.start();
// 守护线程
Thread p2 = new Thread(){
@Override
public void run() {
while(true){
System.out.println("to to to !!! ");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
p2.setDaemon(true);
p2.start();
}
守护线程setDaemon(true)
最新推荐文章于 2024-07-23 15:35:41 发布