title: Policy of worker thread reuse for requests in Tomcat 6
body: <p>I was trying to find some documentation about worker thread reuse policy in web servers especially tomcat 6 but could not find anything easily, so bringing this up with the experts!</p>
  
  <p>As per my understanding, a web serve uses a pool of worker threads to service http requests. </p>
  
  <p>In our application, we do maintain some information in a map with key being the current Thread (sort of a round about way to do thread local).</p>
  
  <p>We recently spotted a bug in our code where we were relying on the fact that when a  session expired (for us configured to be 2 hours), our HttpSessionBindingListener implementing class would receive get the callback and in the method we would use the current thread to query the map and clean up some data. The issue with this approach is that web server would not always give you a worker thread which was associated to the same session 2 hours ago and therefore we were not doing the clean up properly.</p>
  
  <p>After spotting this issue, I am actually confused about the scenario the other way. For us we have seen this code work 80% of the times i.e. getting a worker thread which cleans up the data correctly.</p>
  
  <p>I am little confused on why this ever works? Can somone with knowledge of servlet container internals shed some light on this?</p>