开发者

How to continue object from ThreadLocal in child thread?

I have passed one object in ThreadLocal. Now my current thread going to create new Child thread. I want object from Threa开发者_高级运维dLocal should continue with child thread also.

Is there any way to do so....?

Thank you in advance....


What you need is an InheritableThreadLocal. An InheritableThreadLocal is passed (Java "call by value" semantics) from the parent thread to a child thread when the latter is created.


You may retrieve the object itself from your ThreadLocal via the get() method and pass this reference to you child thread.

If instead you want to share it with your child threads, see other answers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜