I would like to override behaviour so that ExecutorService
calls custom method. When a thread is released I would like to clear all ThreadLocal
variables. Not very familiar with api or maybe there is something which exists there already.
Not sure how thread pool manages threads when they finished their job but I assume it does not destroy them as that would be expensive if it does not destroy them then based on ThreadLocal description:
Each thread holds an implicit reference to its copy of a thread-local
* variable as long as the thread is alive and the {@code ThreadLocal}
* instance is accessible; after a thread goes away, all of its copies of
* thread-local instances are subject to garbage collection (unless other
* references to these copies exist).
I need to clear up ThreadLocal