In a traditional setting, my app does something simple: Accept a request, load some metadata (from a heavy restful call) pertaining to the particular user who sent in that request and store this metadata in a threadlocal bean context (i.e. in a simple hashMap backed into the context's class) so that I can painlessly access these details from any other class in the code path as long as I inject the bean. This works harmoniously with all the other non-threadlocal beans that are injected across my API's lifecycle so there aren't any issues.
However, once I try to do some clever things (kick off some task in a separate thread to mimic a "fire and forget" sort of call) I noticed that wherever the code path (in this new thread) relies on the threadlocal bean I get burned because the details that the hashMap (baked into the context's class) previously held have now disappeared. It makes perfect sense to me why they've evaporated because after all, once I kicked off a new thread, it hasn't "cloned" the parent thread's context into the new child thread's context automatically.
My question is that is there any existing spring framework mechanism (or plain Java for that matter) that I can leverage to make sure that I preserve this information for the new child thread that I fire off? How trivial is it to "deepClone" the original parent thread's context into the new child? If that's a naïve way to do it, can someone recommend some other set up i can engage in before kicking off the thread? Given that I'm looking to maintain this context only for the request's scope I'm unsure if I can use something like Spring's object pooling (after all, I don't want a situation where a new request comes in and a recycle a different/old user's preferences for the new one).