title: Tomcat 8 - MySQL at most 8 connections seen in MySQL Workbench from each tomcat instace
body: <p>Problem:</p>
  
  <p>JDBC connection pool does not seem to have the desired number of initial connections.</p>
  
  <p>It also does not grow to the maximum allowed (at most 8 connections appear to be open per Tomcat instance) thus many clients are blocked waiting for a sql connection</p>
  
  <p>For each Tomcat instance I have a maximum of 8 connections seen on the sql server when using this command:</p>
  
  <pre><code>show processlist;
  </code></pre>
  
  <p>If I set the initialSize to anything under 8 then tomcat will create that number of connections</p>
  
  <ul>
  <li>initialSize == 1 - at Tomcat startup 1 connections are created</li>
  <li>initialSize == 5 - at Tomcat startup 5 connections are created</li>
  <li>initialSize >= 9 - at Tomcat startup 8 connections are created</li>
  </ul>
  
  <p>The connections that exist are functional and the application works while there are few enough requests from clients</p>
  
  <p>In server.xml:</p>
  
  <pre><code>        &lt;Resource auth="Container"
              driverClassName="com.mysql.jdbc.Driver"
              closeMethod="close"
              validationInterval="34000"
              maxWait="3000"
              initialSize="50"
              name="XXX"
              password="XXX"
              removeAbandoned="true"
              removeAbandonedTimeout="350" testWhileIdle="true"
              type="javax.sql.DataSource"
              url="jdbc:mysql://XXXXXXX:3306/XXXXX?characterEncoding=UTF-8"
              username="XXX"
              removeAbandonedOnBorrow="true"
              removeAbandonedOnMaintenance="true"
              validationQuery="SELECT 1"
          /&gt;
  </code></pre>
  
  <p>Additional information
  show global variables like '%connections%';</p>
  
  <ul>
  <li>max_connections          1000</li>
  <li>max_user_connections        0</li>
  </ul>