title: Tomcat limit http sessions, out of memory
body: <p>I have a Tomcat 8 server that frequently runs out of memory.
  My guess as to what is occurring is that Tomcat does not limit the number of http sessions in memory, so if you get enough users, then the server will eventually run out of memory.</p>
  
  <p>I know you can set a session timeout in your web.xml like so,</p>
  
  <pre><code>&lt;session-config&gt;
          &lt;session-timeout&gt;30&lt;/session-timeout&gt;
  &lt;/session-config&gt;
  </code></pre>
  
  <p>But that does not help if you get a lot of users in 30 minutes.
  I searched a lot for some way to limit the number of sessions, but surprisingly did not find much info.  Seems like it would be a common issue, as Tomcat by default is guaranteed to run out of memory on high load.</p>
  
  <p>So, how can you set a limit to the number of http sessions, such that Tomcat will expire the oldest when it reaches that limit?  That seems like the only logical way to not run out of memory.</p>