title: Why does a servlet container synchronise access for multiple requests to a particular resource/ servlet?
body: <blockquote>
    <p>By default, the <code>servlet container</code> loads only a <code>single instance</code> of a
    servlet. <code>Requests</code> serviced by the servlet are <code>run</code> in <code>separate threads</code>,
    but <code>share the same instance</code>. This enables applications to be
    responsive and scalable, since it requires fewer resources and uses
    them efficiently.</p>
  </blockquote>
  
  <p>Almost everyone knows that this is the <code>default threading model</code>.</p>
  
  <p>This question/discussion is a follow-up on <a href="https://stackoverflow.com/questions/8011138/servlet-seems-to-handle-multiple-concurrent-browser-requests-synchronously">this</a> particular stackoverflow thread.</p>
  
  <p>But the output happens to be completely different in my case,</p>
  
  <pre><code>May 21, 2016 1:57:59 PM com.stackoverflow.question8011138.MyServlet doGet
  INFO: [doGet] Test before                        // 1st  thread
  
  May 21, 2016 1:58:26 PM com.stackoverflow.question8011138.MyServlet doGet
  INFO: [doGet] Test before                        // 2nd  thread
  
  May 21, 2016 1:58:59 PM com.stackoverflow.question8011138.MyServlet doGet
  INFO: [doGet] Test after                         // 1st  thread
  
  May 21, 2016 1:59:26 PM com.stackoverflow.question8011138.MyServlet doGet
  INFO: [doGet] Test after                         // 2nd  thread
  </code></pre>
  
  <p>Even though I hit the url mapped to this particlular servlet in 2 browser windows of the same browser, the difference b/w these 2 hitting  ~1 second, but I see the below output </p>
  
  <pre><code>May 21, 2016 1:58:26 PM com.stackoverflow.question8011138.MyServlet doGet
  INFO: [doGet] Test before                        // 2nd  thread
  </code></pre>
  
  <p>after seconds more than that previously mentioned ~1 second,</p>
  
  <p>i.e to this,</p>
  
  <pre><code>May 21, 2016 1:57:59 PM com.stackoverflow.question8011138.MyServlet doGet
  INFO: [doGet] Test before                        // 1st  thread
  </code></pre>
  
  <p>Why?</p>
  
  <p>Clearly, from the output above, the second request is not served after the first has been served completely, but in b/w, contrary to what the <code>OP</code> to that question suggested.</p>
  
  <p>What exactly is going on? </p>
  
  <p>Why 2 different outputs to the same scenario?</p>
  
  <p>The <code>result/ output</code> clearly shows that the server is <code>not synchronizing</code> the <code>2 requests.</code></p>