title: Threadpool and request handling in Tomcat
body: <p>Alright, I've already asked one question regarding this, but needed a bit more info. I'll try to be coherent with my question as much as I can. (Since I am not sure of the concepts).</p>
  
  <p><strong>Background</strong></p>
  
  <p>I have a java web project(dynamic). I am writing Restful webservices. Below is a snippet from my class</p>
  
  <pre><code>/services
  class Services{
   static DataSource ds;
   static{
   ds = createNewDataSource;
   }
  
   /serviceFirst
   @Consumes(Something)
   @produces(Something)
   public List&lt;Data&gt; doFirst(){
    Connection con = ds.getConnection();
    ResultSet res = con.execute(preparedStatement);
    //iterate over res, and create list of Data.
    return list;
   }
  }
  </code></pre>
  
  <p><em>This is a very basic functionality that I have stated here.</em></p>
  
  <p>I've got tomcat server where I've deployed this. I've heard that Tomcat has a threadpool, of size 200 (by default). Now my question is that, how exactly does the threadpool work here.</p>
  
  <p>Say I have two requests coming in at the same time. That means that 2 of the threads from the threadpool will get to work. Does this mean that both the threads will have an instance of my class Services? Because below is how I understand the threads and concurrency.</p>
  
  <pre><code>public class myThread extends Thread(){
      public void run(){
      //do whatever you wan to do here;
      }
  }
  </code></pre>
  
  <p>In the above, when I call start on my Thread it will execute the code in run() method and all the objects that it creates in there, will belong to it.</p>
  
  <p>now, coming back to the Tomcat, is there somewhere a <code>run()</code> method written that instantiates the Services class, and that is how the threadpool handles 200 concurrent requests. (Obviously, I understant they will require 200 cores for them to execute concurrently, so ignore that).</p>
  
  <p>Because otherwise, if tomcat does not have 200 different threads having the same path of execution (i.e. my Services class), then how exactly will it handle the 200 concurrent requests.</p>
  
  <p>Thanks</p>