I have passed one object in ThreadLocal. Now my current thread going to create new Child thread. I want object from ThreadLocal should continue with child thread also.
Is there any way to do so....?
Thank you in advance....
I have passed one object in ThreadLocal. Now my current thread going to create new Child thread. I want object from ThreadLocal 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.