private final ThreadGroup parent; 父线程组对象 String name; 线程组名称 int maxPriority; 最高优先级 boolean destroyed; 是否已销毁 boolean daemon; 是否是守护线程 boolean vmAllowSuspension; 虚拟机自动挂起 int nUnstartedThreads = 0; 未启动线程数 int nthreads; 线程总数 Thread threads[]; 线程数组 int ngroups; 线程组数量 ThreadGroup groups[]; 线程组数组
private ThreadGroup() { // called from C code
this.name = "system";
this.maxPriority = Thread.MAX_PRIORITY;
this.parent = null;
}
public ThreadGroup(String name) {
this(Thread.currentThread().getThreadGroup(), name);
}
public ThreadGroup(ThreadGroup parent, String name) {
this(checkParentAccess(parent), parent, name);
}
private ThreadGroup(Void unused, ThreadGroup parent, String name) {
this.name = name;
this.maxPriority = parent.maxPriority;
this.daemon = parent.daemon;
this.vmAllowSuspension = parent.vmAllowSuspension;
this.parent = parent;
parent.add(this);
}
private static Void checkParentAccess(ThreadGroup parent) {
parent.checkAccess();
return null;
}
确认权限
public final String getName() {
return name;
}
获得线程组名称
public final ThreadGroup getParent() {
if (parent != null)
parent.checkAccess();
return parent;
}
获得父线程组
public final int getMaxPriority() {
return maxPriority;
}
获得最高优先级
public final boolean isDaemon() {
return daemon;
}
是否守护线程
public synchronized boolean isDestroyed() {
return destroyed;
}
是否已销毁
public final void setDaemon(boolean daemon) {
checkAccess();
this.daemon = daemon;
}
设置守护线程
public final void checkAccess() {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkAccess(this);
}
}
确认权限
原文:https://www.cnblogs.com/ctxsdhy/p/12244358.html