ThreadLocal Resource Leak and WeakReference

后端 未结 7 1765
清酒与你
清酒与你 2020-12-30 03:12

My limited understanding of ThreadLocal is that it has resource leak issues. I gather this problem can be remedied through proper use of WeakReferences with ThreadLocal (al

7条回答
  •  庸人自扰
    2020-12-30 03:42

    There shouldn't be such a problem.

    A thread's ThreadLocal reference is defined to exist only as long as the corresponding thread is alive (see the javadoc)-- or put another way, once the thread is not alive, if the ThreadLocal was the only reference to that object, then the object becomes eligible for garbage collection.

    So either you've found a genuine bug and should be reporting it, or you're doing something else wrong!

提交回复
热议问题