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?
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.
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.)
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.
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.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With