在 Eclipse 调试视图中,有一个“显示系统线程”选项:
启用后,Eclipse 会显示许多通常隐藏在线程列表中的线程。它们都在system线程组下:
我的问题是,Java 中是否有“系统线程”的官方概念,或者这只是 Eclipse 的东西?我在谷歌上搜索了一段时间,发现没有提到“Java 系统线程”,所以我猜这是一个 Eclipse 制造的术语?
如果不是这种情况并且这是一个类似于守护线程的 Java 概念,我怎么知道给定的线程是否是“系统”线程?
还有一点我不明白的是,如果我Foo在根system线程组下创建一个新的线程组,然后MyThread在该Foo组下创建一个新线程
public class Test2 {
public static void main(String[] args) {
ThreadGroup threadGroup = new ThreadGroup(getRootThreadGroup(), "Foo");
new Thread(threadGroup, () -> {
System.out.println("hello");
}, "MyThread").start();
}
// This will return the root "system" thread group
public static ThreadGroup getRootThreadGroup () {
ThreadGroup currentGroup = Thread.currentThread().getThreadGroup();
while (currentGroup != null) {
ThreadGroup parent = currentGroup.getParent();
if (parent == null) {
return currentGroup;
}
else {
currentGroup = parent;
}
}
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
然后 Eclipse 显示这MyThread是一个系统线程:
因此,在这种情况下,Eclipse 是否将我的线程误认为“系统线程”,或者这是创建“系统线程”的实际方法,无论是什么?
| 归档时间: |
|
| 查看次数: |
192 次 |
| 最近记录: |