Context:
static ThreadLocal<MyType> threadLocalMyType = ...
What i’d like is to say something like:
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...]
}
One way would be to handle this manually:
ThreadLocal(extend it)static)Mapof Threads and valuesAlternatively, with some reflection (
getDeclaredMethod()andsetAccessible(true)), you can:Thread.getThreads()yourThreadLocal.getMap(thread)(for each of the above threads)map.getEntry(yourThreadLocal)The 1st is more preferable.