privatevoidinit(ThreadGroup g, Runnable target, String name, long stackSize) { Threadparent= currentThread(); SecurityManagersecurity= System.getSecurityManager(); // 确定ThreadGroup if (g == null) { /* Determine if it's an applet or not */
/* If there is a security manager, ask the security manager what to do. */ if (security != null) { g = security.getThreadGroup(); }
/* If the security doesn't have a strong opinion of the matter use the parent thread group. */ if (g == null) { g = parent.getThreadGroup(); } } // 增加该线程组中未启动线程的数目 g.addUnstarted();
this.group = g; // 是否为守护线程/优先级都由父亲线程确定 this.daemon = parent.isDaemon(); this.priority = parent.getPriority(); this.name = name.toCharArray(); this.target = target; setPriority(priority); // 创建ThreadLocal变量对应的ThreadLocalMap if (parent.inheritableThreadLocals != null) this.inheritableThreadLocals = ThreadLocal.createInheritedMap(parent.inheritableThreadLocals); /* Stash the specified stack size in case the VM cares */ this.stackSize = stackSize;
public T get() { Threadt= Thread.currentThread(); ThreadLocalMapmap= getMap(t); if (map != null) { ThreadLocalMap.Entrye= map.getEntry(this); if (e != null) return (T)e.value; } return setInitialValue(); }