title: Threads in Spring
body: <p>I have a Web application using spring and hibernate and struts (it runs on Tomcat)</p>
  
  <p>The call sequence is something like this...</p>
  
  <p>Struts action calls spring service bean which in turn calls Spring DAO bean. The DAO implementation is a Hibernate implementation.</p>
  
  <p><strong>The question is</strong>
  Would all my spring beans be running in the same thread ?
  Can I store something in the ThreadLocal and get it in another bean?</p>
  
  <p>I am quite sure this would not work in Stateless Session Bean.
  The EJB container can (or will) spawn a new thread for every call to the session bean</p>
  
  <p><strong>Will the spring container do the same? i.e. run all beans in the same thread ?</strong></p>
  
  <p>When I tried a JUnit test - I got the same id via Thread.currentThread().getId() in the Test Case and the two beans- which leads me to believe there was only one thread in action</p>
  
  <p>Or is the behavior unpredictable?
  Or will it change when running on Tomcat server ?</p>
  
  <p><strong>Clarification</strong>
  I do not wish to exchange data between two threads. I want to put data in the ThreadLocal and be able to retrieve it from all beans in the call stack. This will work only if all beans are in the same thread</p>