java中如果主线程关闭(main),那么创建的其它子线程还能运行不?我的例子:
public class t {
public static void main(String[] args) {
System.out.println("kaishi");
asd th = new asd();
th.start();
System.out.println(System.currentTimeMillis());
System.out.println("tuichu");
System.out.println(Thread.currentThread().getName()+System.currentTimeMillis());
System.exit(0);
}
}
class asd extends Thread {
public void run() {
while (true) {
System.out.println(Thread.currentThread().getName()+System.currentTimeMillis());
}
}
}
结果是kaishi
1214278000531
tuichu
main1214278000531
Thread-01214278000531
Thread-01214278000531
Thread-01214278000531
Thread-01214278000531
Thread-01214278000531
Thread-01214278000531
Thread-01214278000531
Thread-01214278000531
Thread-01214278000531
Thread-01214278000531
Thread-01214278000531
Thread-01214278000531
Thread-01214278000531
Thread-01214278000531
Thread-01214278000531
Thread-01214278000531
Thread-01214278000531
Thread-01214278000531
Thread-01214278000531
Thread-01214278000531
Thread-01214278000531这个能说明主线程关闭后子线程也关闭吗?
[b]问题补充:[/b]
那主线程(main)关闭是不是进程关闭呢?
[b]问题补充:[/b]
既然System.exit(0); 是退出jvm,那怎么退出后还会运行一段时间的新建线程呢?