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.
精彩评论