Java Cached thread pool and thread local

前端 未结 3 543
余生分开走
余生分开走 2020-12-16 23:15

I have a question about java and concurrency.

Let say I have a ThreadLocal variable called \'a\'. And I use a CachedThreadPool to obtain new threads. When a thread i

3条回答
  •  旧时难觅i
    2020-12-17 00:16

    If the thread is returned to the pool, the ThreadLocal variable will still be attached to it. When using ThreadLocals with pools, you have to be careful to be able to set when the thread is pulled from the pool and unset before it is returned.

提交回复
热议问题