ThreadLocal and ThreadPool do not interact with each other if you do not.
What you can do is the only ThreadLocal that saves all the state you want to save and have it reset when the task completes. You can override ThreadPoolExecutor.afterExecute (or beforeExecute) to clear ThreadLocal (s)
From ThreadPoolExecutor
protected void afterExecute(Runnable r, Throwable t) { }
Instead of tracking all ThreadLocals, you can clear them immediately.
protected void afterExecute(Runnable r, Throwable t) {
Peter Lawrey
source share