Do you need to call remove on a thread local if you are not deploying in a server environment, even if the app uses a cached thread pool?
public static ThreadLocal<Integer> i = new ThreadLocal<Integer>(){{
public Integer initialValue(){return 3;}
};
As per the javadoc for ThreadLocal
:
... after a thread goes away, all of its copies of thread-local instances are subject to garbage collection ...
If the thread may still be around, and you want the resource dereferenced, better call remove()
.
Sounds like you might want to consider using a simple local variable if you want to clear it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With