Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat 7 - Ignoring db conections pool parameters (DBCP)

We are facing a problem that the number of connections made to the database explodes during restarts of Tomcat 7.

Our configurations are below, set on Tomcat's context.xml:

<Resource auth="Container"
            driverClassName="oracle.jdbc.driver.OracleDriver"
            initialSize="1"
            maxActive="10"
            maxAge="600000"
            maxIdle="5"
            maxOpenPreparedStatements="200"
            maxWait="10000"
            minEvictableIdleTimeMillis="60000"
            minIdle="0"
            name="jdbc/backoffice"
            password="backoffice"
            poolPreparedStatements="true"
            rollbackOnReturn="true"
            testWhileIdle="true"
            timeBetweenEvictionRunsMillis="6000000"
            type="javax.sql.DataSource"
            url="jdbc:oracle:thin:@127.0.0.1:1521:DATABASE"
            username="backoffice"
            validationQuery="SELECT SYSDATE FROM DUAL"
            removeAbandoned="true"
            removeAbandonedTimeout="60"
            logAbandoned="true"
    />

After a restart of Tomcat, the opened connections number gets close to 700. A redeploy of the war (rename to ".war_bk" e rename back to ".war") resolves the problem.

Why this is happening? What can we do differently?

like image 689
Marcelo Dias Avatar asked May 07 '19 13:05

Marcelo Dias


People also ask

What is DBCP in Tomcat?

Tomcat DBCP is just a renamed version of Apache Commons DBCP, with also a different internal package name prefix. At build time, Tomcat fetches the Commons DBCP sources (the version depends on the Tomcat version, for instance Tomcat 7.0. 27 uses Commons DBCP 1.4), and does package name replacement ( org.

What is the default value of Defaultautocommit attribute of Commons DBCP or Tomcat JDBC pool?

Common Attributes. These attributes are shared between commons-dbcp and tomcat-jdbc-pool, in some cases default values are different. (boolean) The default auto-commit state of connections created by this pool. If not set, default is JDBC driver default (If not set then the setAutoCommit method will not be called.)

What is DBCP connection pool?

The DBCP Component Opening a connection per user can be unfeasible in a publicly-hosted Internet application where the number of simultaneous users can be very large. Accordingly, developers often wish to share a "pool" of open connections between all of the application's current users.

Where do you configure a database connection pool in Tomcat server?

For configuring the connection pool for SQLServer you need to configure the SQLServer drivers as explained in the Microsoft SQL Server section and put the jar file into the TOMCAT_HOME/lib folder. Note that database name, username and password must be defined directly in the URL.


1 Answers

Add values also for maxConnLifetimeMillis

maxConnLifetimeMillis -1 The maximum lifetime in milliseconds of a connection. After this time is exceeded the connection will fail the next activation, passivation or validation test. A value of zero or less means the connection has an infinite lifetime.

And maxTotal

maxTotal 8 The maximum number of active connections that can be allocated from this pool at the same time, or negative for no limit.

You can change validationQuery to simpler query

validationQuery="SELECT 1 FROM DUAL"
like image 149
user7294900 Avatar answered Sep 29 '22 21:09

user7294900