对于this和当前线程的一些理解

在学习这个InheritableThreadLocal类的时候,我对于有个地方一直没有理解,我发现了盲点。

 1   private void init(ThreadGroup g, Runnable target, String name,
 2                       long stackSize, AccessControlContext acc,
 3                       boolean inheritThreadLocals) {
 4         //..........
 5         Thread parent = currentThread();
 6         //..........
 7         if (inheritThreadLocals && parent.inheritableThreadLocals != null)
 8             this.inheritableThreadLocals =
 9                 ThreadLocal.createInheritedMap(parent.inheritableThreadLocals);
10         /* Stash the specified stack size in case the VM cares */
11         this.stackSize = stackSize;
12 
13         /* Set thread ID */
14         tid = nextThreadID();
15     }

在这个地方,我的思想出现了问题,对于这个currentThread得到了当前线程,这里没有问题,然后设置this.inheritableThreadLocals=

ThreadLocal.createInheritedMap(parent.inheritableThreadLocals);

我的问题来了。。。为什么这个this可以代表子线程,当前线程不是父线程吗?我对于这个问题感觉深深的不解,

我思考了良久,得出了一个结论,我TM真是个sb,啊啊啊啊啊啊为什么会把这个this当作子线程呢,这明明是个对象啊

,代表子对象的引用啊,线程和对象不是一个东西啊。。。。。我给自己整吐了。。

好了。。吐槽结束了,希望大家不要放跟我一样的错误

猜你喜欢

转载自www.cnblogs.com/cold-windy/p/11742340.html