读书人

施用TreadPool时的ThreadLocal示例

发布时间: 2012-06-30 17:20:12 作者: rapoo

使用TreadPool时的ThreadLocal示例

转载,原文链接:http://www.cnblogs.com/goofy/archive/2011/11/11/2245907.html

?

???public voidset(T value) {

???????Thread t = Thread.currentThread();

???????ThreadLocalMap map = getMap(t);

???????if (map!= null)

???????????map.set(this, value);

???????else

???????????createMap(t, value);

}

?}
?});
?
//没有set的Runnable
?pool.execute(new Runnable() {
?@Override
public void run() {
System.out.println("" + Thread.currentThread() + "not seted bol:" + bol.get());
}
?});
}
?}

读书人网 >开源软件

热点推荐