title: When exactly is the HttpSession expired (starts being eligible for destroying - not necessarily destroyed yet)?
body: <p>I would like to know when <strong>exactly</strong> an HttpSession would be <strong>expired</strong> (not the same as destroyed)?   </p>
  
  <p><strong>I am trying to figure out if session.getLastAccessedTime() + (session.getMaxInactiveInterval() * 1000) will give me the exact time in milliseconds of session expiry each time a request comes with the same session id!</strong></p>
  
  <p>From the javadocs:  </p>
  
  <blockquote>
    <p>long getLastAccessedTime()  </p>
  
  <pre><code>  Returns the last time the client sent a request associated with this session, as the number of milliseconds since midnight January 1, 1970 GMT, and marked by the time the container received the request.    
  </code></pre>
    
    <p>int  getMaxInactiveInterval()   </p>
  
  <pre><code>  Returns the maximum time interval, in seconds, that the servlet container will keep this session open between client accesses.  
  </code></pre>
  </blockquote>
  
  <p>Lets say we have the following:<br>
  Treq1 - <code>the time the container received the 1st request</code>  (HttpSession.lastAccessedTime)<br>
  Tresp1 - <code>the time the container sends the 1st response</code><br>
  Preq1 - <code>the time period between Treq1 and Tresp1 (the time period that the server processes the 1st request</code><br>
  Treq2 - <code>the time the container received the 2nd request</code>  (HttpSession.lastAccessedTime)<br>
  Preq1req2 - <code>the time period between Treq1 and Treq2 (the time between requests entering the container)</code><br>
  Presp1req2 - <code>the time period between Tresp1 and Treq2 (the time between the 1st response exiting the container and the 2nd request entering the container)</code>  </p>
  
  <p>So now, <strong>when does the server calculate the session as expired?</strong> When:<br>
  1. Treq1 + maxInactiveInterval &lt; Treq1 + Preq1req2 => <strong>maxInactiveInterval &lt; Preq1req2</strong><br>
  2. Tresp1 + maxInactiveInterval &lt; Tresp1 + Presp1req2 => <strong>maxInactiveInterval &lt; Presp1req2</strong>  </p>
  
  <p><strong>This part, <code>the servlet container will keep this session open between client accesses</code> is a bit confusing. Does it mean between requests entering the container or between response exiting and requests entering?</strong>  </p>
  
  <p><em>On a side note</em>, <strong><em>I know that the session might not be destroyed at the exact time of expiry</em></strong>, but I don't know yet if it is destroyed before any request processing logic occurs in the container. I am referring to the request that holds an expired session id.</p>
  
  <p>Kind Regards,<br>
  Despot</p>