ThreadLocal Resource Leak and WeakReference

后端 未结 7 1568
清酒与你
清酒与你 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 04:04

    Just to add on to what @Neil Coffey said, this shouldn't be a problem as long as your ThreadLocal instance is static. Because you keep calling get() on a static instance, it should always hold the same reference to your simple date formatter. Therefore, as Neil said, when the Thread is terminated, the only instance of simple date formatter should be eligible for garbage collection.

    If you have numbers or some other form of debugging that shows this introducing resource issues, then that's another story. But I believe as is it shouldn't be a problem.

    0 讨论(0)
提交回复
热议问题