线程里开启线程,线程里又开启线程,最原始的线程关闭后,后面的线程能否运行?

线程里开启线程,线程里又开启线程,最原始的线程关闭后,后面的线程能否运行?

代码:

public class ThreadTest {

	public static void main(String[] args) throws Exception {
		Thread a = new Thread() {
			public void run() {
				Thread b = new Thread() {
					public void run() {
						Thread c = new Thread() {
							public void run() {
								System.out.println("C1>>>>>>>>>>start");
								while (true) {
									try {
										Thread.sleep(100);
									} catch (InterruptedException e) {
										e.printStackTrace();
									}
									System.out.println("C2>>>>>>>>>>ing>>");
								}
							}
						};
						System.out.println("B1>>>>>>>>>>start");
						c.start();
						while (true) {
							try {
								Thread.sleep(100);
							} catch (InterruptedException e) {
								e.printStackTrace();
							}
							System.out.println("B2>>>>>>>>>>ing>>");
						}
					}
				};
				System.out.println("A1>>>>>>>>>>start");
				b.start();
				while (true) {
					try {
						Thread.sleep(100);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					System.out.println("A2>>>>>>>>>>ing>>");
				}
			}
		};
		System.out.println("Main1>>>>>>>>>>");
		a.start();
		System.out.println("Main2>>>>>>>>>>");
		Thread.sleep(1000);
		a.stop();
		System.out.println("Main3>>>>>>>>>>");
	}
}

打印:

Main1>>>>>>>>>>
Main2>>>>>>>>>>
A1>>>>>>>>>>start
B1>>>>>>>>>>start
C1>>>>>>>>>>start
B2>>>>>>>>>>ing>>
C2>>>>>>>>>>ing>>
A2>>>>>>>>>>ing>>
B2>>>>>>>>>>ing>>
C2>>>>>>>>>>ing>>
A2>>>>>>>>>>ing>>
C2>>>>>>>>>>ing>>
A2>>>>>>>>>>ing>>
B2>>>>>>>>>>ing>>
A2>>>>>>>>>>ing>>
B2>>>>>>>>>>ing>>
C2>>>>>>>>>>ing>>
B2>>>>>>>>>>ing>>
A2>>>>>>>>>>ing>>
C2>>>>>>>>>>ing>>
B2>>>>>>>>>>ing>>
A2>>>>>>>>>>ing>>
C2>>>>>>>>>>ing>>
A2>>>>>>>>>>ing>>
B2>>>>>>>>>>ing>>
C2>>>>>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>>
C2>>>>>>>>>>ing>>
B2>>>>>>>>>>ing>>
C2>>>>>>>>>>ing>>
C2>>>>>>>>>>ing>>
B2>>>>>>>>>>ing>>
B2>>>>>>>>>>ing>>
C2>>>>>>>>>>ing>>
C2>>>>>>>>>>ing>>
B2>>>>>>>>>>ing>>
B2>>>>>>>>>>ing>>
C2>>>>>>>>>>ing>>
C2>>>>>>>>>>ing>>
B2>>>>>>>>>>ing>>
B2>>>>>>>>>>ing>>
C2>>>>>>>>>>ing>>
B2>>>>>>>>>>ing>>

结论:
thread.stop能终止调用者本身和run里开启的线程,但不能终止run里开启线程的run里开启的线程。
说人话就是:只能终止自己和下一层,下下层及下下下层等等后续的线程都无法终止。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值