title: Why does my Tomcat only open 8 JDBC connections
body: <p>When setting up the database connections in Tomcat 8, for some reason Tomcat is not following what I configured in the context.xml, with as result that I run out of connections, leading to resource contentions at the application server side (BLOCKED/WAITING threads). I always have 8 connections (show processlist in mariadb/mysql) after the pool initializes. My configuration states a minimum of 10 connections and a maximum of 100 connections.</p>
  
  <p>I tested different configurations, but this does not make any difference at all, which is strange at least. The context.xml is used else it would not be able to connect to the database at all.</p>
  
  <p>What is happening here? Why only 8 connections?</p>
  
  <p>Software versions:
  - MySQL JDBC driver: Latest (5.1.35) 
  - Java 1.8.0_05</p>
  
  <p>I also observed with with my previous setup: Tomcat 7, Java 1.7, older MySQL JDBC drivers, MySQL instead of MariaDB. So the problem does not seem directly version related.</p>
  
  <p>Show processlist output (Showing the 8 processes):</p>
  
  <pre><code>| Id    | User          | Host          | db                | Command | Time | State     | Info            | Progress |                                                                     
  +-------+---------------+---------------+-------------------+---------+------+-----------+-----------------+----------+
  | 71153 | root          | localhost     | vnitdatacollector | Query   |    0 | init      | show processlist|    0.000 |                                                                     
  | 73473 | vnit_datacoll | virt005:58585 | vnitdatacollector | Sleep   |    0 |           | NULL            |    0.000 |                                                                     
  | 73474 | vnit_datacoll | virt005:58586 | vnitdatacollector | Sleep   |    0 |           | NULL            |    0.000 |                                                                     
  | 73482 | vnit_datacoll | virt005:58606 | vnitdatacollector | Query   |    0 | update    | INSERT INTO ... |    0.000 |
  | 73483 | vnit_datacoll | virt005:58607 | vnitdatacollector | Sleep   |    0 |           | NULL            |    0.000 |                                                                     
  | 73485 | vnit_datacoll | virt005:58618 | vnitdatacollector | Query   |    0 | query end | INSERT INTO ... |    0.000 |
  | 73487 | vnit_datacoll | virt005:58624 | vnitdatacollector | Sleep   |    0 |           | NULL            |    0.000 |                                                                     
  | 73488 | vnit_datacoll | virt005:58634 | vnitdatacollector | Sleep   |    0 |           | NULL            |    0.000 |                                                                     
  | 73489 | vnit_datacoll | virt005:58637 | vnitdatacollector | Query   |    7 | update    | INSERT INTO ... |    0.000 |
  +-------+---------------+---------------+-------------------+---------+------+-----------+-----------------+----------+
  </code></pre>
  
  <p>I have the following context.xml configuration:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Context&gt;
    &lt;Resource 
      name="jdbc/dbaccess" 
      auth="Container" 
      type="javax.sql.DataSource"
      maxActive="100" 
      maxIdle="100"
      minIdle="10"
      maxWait="1000"
      initialSize="10"
      minEvictableIdleTimeMillis="5000"
      testOnBorrow="true"
      validationQuery="SELECT 1" 
      timeBetweenEvictionRunsMillis="5000" 
      testWhileIdle="true"
      removeAbandoned="true" 
      removeAbandonedTimeout="60" 
      logAbandoned="true"
      username="some_user" 
      password="{the password}" 
      driverClassName="com.mysql.jdbc.Driver"
      url="jdbc:mysql://dbserver:3306/dbaccess?useFastDateParsing=false&amp;amp;jdbcCompliantTruncation=false"
    /&gt;
    &lt;Resource
      name="mail/emailconnection"
      auth="Container"
      type="javax.mail.Session"
      mail.smtp.host="some.stmp.server"
    /&gt;             
  &lt;/Context&gt;
  </code></pre>
  
  <p>The following thread issue then shows up after a (short) period:</p>
  
  <pre><code>"Thread-495" #517 daemon prio=5 os_prio=0 tid=0x00007f678c040800 nid=0x1642 waiting on condition [0x00007f67848f4000]
  java.lang.Thread.State: WAITING (parking)
      at sun.misc.Unsafe.park(Native Method)
      - parking to wait for  &lt;0x00000000f21933f0&gt; (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
      at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
      at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
      at org.apache.tomcat.dbcp.pool2.impl.LinkedBlockingDeque.takeFirst(LinkedBlockingDeque.java:582)
      at org.apache.tomcat.dbcp.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:439)
      at org.apache.tomcat.dbcp.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:360)
      at org.apache.tomcat.dbcp.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:118)
      at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1412)
      at com.hipersonik.util.ServiceLocator.getConnection(ServiceLocator.java:32)
  </code></pre>