Tomcat DataSource - Max Active Connections
<p>I set max active connections to 1 using the below code :</p>
<pre><code>    ConnectionPool initializePool(DataSource dataSource) {
    if (!(org.apache.tomcat.jdbc.pool.DataSource.class.isInstance(dataSource))) {
        return null;
    }
    org.apache.tomcat.jdbc.pool.DataSource tomcatDataSource = (org.apache.tomcat.jdbc.pool.DataSource) dataSource;
    final String poolName = tomcatDataSource.getName();
    try {
        ConnectionPool pool = tomcatDataSource.createPool();
        pool.getPoolProperties().setMaxActive(1);
        pool.getPoolProperties().setInitialSize(1);
        pool.getPoolProperties().setTestOnBorrow(true);
        return pool;
    } catch (SQLException e) {
        logger.info(String.format(&quot; !--! creation of pool failed for %s&quot;, poolName), e);
    }
    return null;
}
</code></pre>
<p>Now using threads , I have opened number of concurrent connections to DB. I also printed out the current active number of connections using the below listed code</p>
<pre><code>System.out.println(&quot;Current Active Connections = &quot; + ((org.apache.tomcat.jdbc.pool.DataSource) datasource).getActive());
System.out.println(&quot;Max Active Connections = &quot; + ((org.apache.tomcat.jdbc.pool.DataSource) datasource).getMaxActive());
</code></pre>
<p>I see results similar to below. Active connections is being displayed as more than 1. However I want to restrict the max active connections to 1. Are there any other parameters that I need to set?</p>
<blockquote>
<p>Current Active Connections = 9</p>
<p>Max Active Connections = 1</p>
</blockquote>
<p>EDIT: However when I try with 15 or 20 as max active , it is always limited to 15 or 20 respectively.</p>