码迷,mamicode.com
首页 > 其他好文 > 详细

ThreadGroup

时间:2020-01-31 01:03:07      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:start   string   uri   security   zed   void   sync   check   group   

一、源码

1、属性

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[];
线程组数组

  

2、构造方法

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);
}

  

3、一般方法

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);
    }
}
确认权限

  

 

ThreadGroup

标签:start   string   uri   security   zed   void   sync   check   group   

原文地址:https://www.cnblogs.com/ctxsdhy/p/12244358.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!