'DBPC2 Configuration

I'm trying to optimize my JDBC connexion on my Tomcat application, but when I'm trying to launch a stress campaign, after thousands of requests (random) I have the following error:

org.apache.tomcat.dbcp.dbcp2.SwallowedExceptionLogger.onSwallowException An internal object pool swallowed an Exception.
    org.apache.tomcat.dbcp.dbcp2.LifetimeExceededException: The lifetime of the connection [PT5.001668S] milliseconds exceeds the maximum permitted value of [PT5S] milliseconds

Here is my context.xml configuration file:

 <Context>
    <Resource name="jdbc/MyApp" 
          auth="Container" 
          type="javax.sql.DataSource" 
          maxTotal="500"
          maxIdle="200" 
          maxWaitMillis="1000" 
          testWhileIdle="false"
          testOnBorrow="false"
          testOnReturn="false"
          validationQuery="SELECT 1"
          timeBetweenEvictionRunsMillis="5000"
          maxConnLifetimeMillis="10000"
          removeAbandonedOnBorrow="true" 
          removeAbandonedTimeout="1" 
          logAbandoned="true"
          closeMethod="close"
          minEvictableIdleTimeMillis="5000"
          driverClassName="com.mysql.cj.jdbc.Driver" />

Those tests are performed on a small server and Thread Duration might be longer than my production one (which is working fine with those parameters). btw, just need to ensure there is no hidden bug behind that and I would need to clearly understand the impact of each parameter (which is to be honest quite complicated for me...).

I had initially an issue with the number of Threads Connected (max Thread set to 500 on MySQL) on my MySQL Server, by reducing the idle time I was able to reduce it, but I need to find a good compromise I think...



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source