【发布时间】:2016-08-09 06:03:14
【问题描述】:
这是我的代码
package pe.entel.ftp;
public class Myclass implements Runnable {
public void run() {
System.out.println(Thread.currentThread().getName());
}
public static void main(String[] args) {
Myclass runnable = new Myclass();
ThreadGroup tg1 = new ThreadGroup("Parent ThreadGroup");
for (int i = 0; i < 100; i++) {
Thread t1 = new Thread(tg1, runnable, i + "");
t1.start();
System.out.println("Thread Group Name: " + tg1.getName());
}
while (tg1.isDestroyed()) {
System.out.println("yes success");
}
System.out.println("completed");
}
}
而我的 o/p 部分是
Thread Group Name: Parent ThreadGroup
Thread Group Name: Parent ThreadGroup
Thread Group Name: Parent ThreadGroup
Thread Group Name: Parent ThreadGroup
Thread Group Name: Parent ThreadGroup
completed
84
86
88
90
92
94
96
98
95
97
99
这里我无法准确预测线程组何时完成执行。甚至,用于检查线程组是否被破坏的while循环也不起作用。即使在打印完成后,一些线程仍在执行。
【问题讨论】:
标签: java multithreading