50,879
社区成员
![](https://csdnimg.cn/release/cmsfe/public/img/topic.427195d5.png)
![](https://csdnimg.cn/release/cmsfe/public/img/me.40a70ab0.png)
![](https://csdnimg.cn/release/cmsfe/public/img/task.87b52881.png)
![](https://csdnimg.cn/release/cmsfe/public/img/share-circle.3e0b7822.png)
public class Main {
public static void main(String[] args) {
Thread tA = new Thread(() -> {
for(int i = 0; i < 10; i++){
System.out.println("线程A "+i);
}
});
Thread tB = new Thread(() -> {
for(int i = 0; i < 10; i++){
System.out.println("线程B "+i);
if(i == 6){
System.out.println("程序强制退出");
System.exit(0);
}
}
});
tA.start();
tB.start();
}
我觉得这个应该是结束当前线程和他的子线程
public class Main {
public static void main(String[] args) {
Thread tA = new Thread(() -> {
for(int i = 0; i < 10; i++){
System.out.println("线程A "+i);
}
});
Thread tB = new Thread(() -> {
for(int i = 0; i < 10; i++){
System.out.println("线程B "+i);
if(i == 6){
System.out.println("程序强制退出");
System.exit(0);
}
}
});
tA.start();
tB.start();
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("hello");
这个是 System.exit();方法的注释Terminates the currently running Java Virtual Machine,确实是终止java虚拟机tA.start();
tB.start();
System.exit(0);