title: Propagating ThreadLocal to a new Thread fetched from a ExecutorService
body: <p>I'm running a process in a separate thread with a timeout, using an ExecutorService and a Future (example code <a href="https://stackoverflow.com/questions/1164301/how-do-i-call-some-blocking-method-with-a-timeout-in-java/1164333#1164333">here</a>) (the thread "spawning" takes place in a AOP Aspect).</p>
  
  <p>Now, the main thread is a <a href="http://www.jboss.org/resteasy" rel="noreferrer">Resteasy</a> request. Resteasy uses one ore more ThreadLocal variables to store some context information that I need to retrieve at some point in my Rest method call. Problem is, since the Resteasy thread is running in a new thread, the ThreadLocal variables are lost.</p>
  
  <p>What would be the best way to "propagate" whatever ThreadLocal variable is used by Resteasy to the new thread? It seems that Resteasy uses more than one ThreadLocal variable to keep track of context information and I would like to "blindly" transfer all the information to the new thread.</p>
  
  <p>I have looked at subclassing <code>ThreadPoolExecutor</code> and using the <a href="http://download.oracle.com/javase/6/docs/api/java/util/concurrent/ThreadPoolExecutor.html#beforeExecute%28java.lang.Thread,%20java.lang.Runnable%29" rel="noreferrer">beforeExecute</a> method to pass the current thread to the pool, but I couldn't find a way to pass the ThreadLocal variables to the pool.</p>
  
  <p>Any suggestion?</p>
  
  <p>Thanks</p>