Jon*_*s N 4 java multithreading thread-local
语境:
static ThreadLocal<MyType> threadLocalMyType = ...
Run Code Online (Sandbox Code Playgroud)
我想要的是说:
for (ThreadLocalEntry e: threadLocalMyType.getMapLikeThing() {
// Thread t = e.getKey();
// I don't need the thread value right now, but it might be useful for
// something else.
MyType theMyType = e.getValue();
// [...do something with theMyType...]
}
Run Code Online (Sandbox Code Playgroud)
一种方法是手动处理:
ThreadLocal(扩展)static)Map线程和值或者,通过一些反射(getDeclaredMethod()和setAccessible(true)),您可以:
Thread.getThreads()yourThreadLocal.getMap(thread)(对于上述每个线程)map.getEntry(yourThreadLocal)第一个是更优选的.
| 归档时间: |
|
| 查看次数: |
2767 次 |
| 最近记录: |