: Undefined array key "dark" in /www/wwwroot/wql_luoqin_ltd/wp-content/themes/Sakura/functions.php on line 694
class="post-template-default single single-post postid-1971 single-format-standard wp-custom-logo chinese-font ">
public T get() {
//(1)获取当前线程
Thread t = Thread.currentThread();
//(2)获取当前线程的threadLocals变量
ThreadLocalMap map = getMap(t);
//(3)如果threadLocals变量不为null,就可以在map中查找到本地变量的值
if (map != null) {
ThreadLocalMap.Entry e = map.getEntry(this);
if (e != null) {
@SuppressWarnings("unchecked")
T result = (T)e.value;
return result;
}
}
//(4)执行到此处,threadLocals为null,调用该更改初始化当前线程的threadLocals变量
return setInitialValue();
}
public void remove() {
//获取当前线程绑定的threadLocals
ThreadLocalMap m = getMap(Thread.currentThread());
//如果map不为null,就移除当前线程中指定ThreadLocal实例的本地变量
if (m != null)
m.remove(this);
}
二,ThreadLocalMap的源码
1,属性的设置
static class ThreadLocalMap {
//Entry初始容量
private static final int INITIAL_CAPACITY = 16;
//Entry对象
private ThreadLocal.ThreadLocalMap.Entry[] table;
//Entry的大小
private int size = 0;
//阈值
private int threshold;
//阈值设置
private void setThreshold(int len) {
this.threshold = len * 2 / 3;
}
private static int nextIndex(int i, int len) {
return i + 1 < len ? i + 1 : 0;
}
private static int prevIndex(int i, int len) {
return i - 1 >= 0 ? i - 1 : len - 1;
}
2,构造方法
ThreadLocalMap(ThreadLocal<?> firstKey, Object firstValue) {
this.table = new ThreadLocal.ThreadLocalMap.Entry[16];
int i = firstKey.threadLocalHashCode & 15;
this.table[i] = new ThreadLocal.ThreadLocalMap.Entry(firstKey, firstValue);
this.size = 1;
this.setThreshold(16);
}
private ThreadLocalMap(ThreadLocal.ThreadLocalMap parentMap) {
ThreadLocal.ThreadLocalMap.Entry[] parentTable = parentMap.table;
int len = parentTable.length;
this.setThreshold(len);
this.table = new ThreadLocal.ThreadLocalMap.Entry[len];
ThreadLocal.ThreadLocalMap.Entry[] var4 = parentTable;
int var5 = parentTable.length;
for(int var6 = 0; var6 < var5; ++var6) {
ThreadLocal.ThreadLocalMap.Entry e = var4[var6];
if (e != null) {
ThreadLocal<Object> key = (ThreadLocal)e.get();
if (key != null) {
Object value = key.childValue(e.value);
ThreadLocal.ThreadLocalMap.Entry c = new ThreadLocal.ThreadLocalMap.Entry(key, value);
int h;
for(h = key.threadLocalHashCode & len - 1; this.table[h] != null; h = nextIndex(h, len)) {
}
this.table[h] = c;
++this.size;
}
}
}
}
Comments | NOTHING
Warning: Undefined variable $return_smiles in /www/wwwroot/wql_luoqin_ltd/wp-content/themes/Sakura/functions.php on line 1109