When and how should I use a ThreadLocal variable?

前端 未结 25 1941
再見小時候
再見小時候 2020-11-22 12:35

When should I use a ThreadLocal variable?

How is it used?

25条回答
  •  孤街浪徒
    2020-11-22 13:21

    Caching, sometime you have to calculate the same value lots of time so by storing the last set of inputs to a method and the result you can speed the code up. By using Thread Local Storage you avoid having to think about locking.

提交回复
热议问题