I have a InheritableThreadLocal variable which I want to pass to another child Thread allocated by the Thread pool of the EJB container as a result of a Async call to a public EJB method. The parent caller initiating the Async call is a REST resource which is a Stateless EJB. InheritableThreadLocal passes value to its child thread only when the child thread is created new. Once a thread is created in the pool it never destroys the Thread till the server is bounced.
Considering the above facts, the child thread for my case comes from a Threadpool maintained by the EJB container. The InheritableThreadLocal passing value to its child thread only when Resource is invoked for the first time after a server starts or if a brand new Thread which just got created in Threadpool is allocated as a child thread. In all other cases I am getting the initial value what got assigned to the child thread from the pool when the Thread got created and allocated for the 1st time.
I am running my code on IBM WebSphere and Passing the ThreadLocal value as a method parameter in the Async call is not an option.
How I can reassign the ThreadLocal value so that for each run I can get the current value assigned to the child thread?
I found the below link which is somewhat similar but for my case the ThreadPool is what provided by the EJB container.
Propagating ThreadLocal to a new Thread fetched from a ExecutorService