9

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?

Marcelo Dias
  • 409
  • 2
  • 18
  • Is it possible that Tomcat isn't shut down cleanly? I have seen this before, Tomcat's `java` process is still running but released the TCP port and thus the next startup works fine. Maybe something similar happens when you re-deploy. –  May 07 '19 at 13:31
  • @a_horse_with_no_name We always check if the tomcat is down (before issue start) using "ps -ef | grep java". And we kill it if it isn't already down. Anyway, we think that if is it the problem, the connection number would be close to the double of set to the pool limits, but it gets closed to 700. – Marcelo Dias May 07 '19 at 17:51
  • Which OS is tomcat running on? How do you restart tomcat? Please post the exact command. – LMC May 07 '19 at 23:17
  • @LuisMuñoz it is running on CentOS. "service tomcat stop", after it we check using "ps -ef | grep tomcat" and start using "service tomcat start". – Marcelo Dias May 08 '19 at 13:26
  • Check context.xml inside the war, there might be duplicated resources. – LMC May 08 '19 at 13:46
  • We already checked it. It is empty. Tks. – Marcelo Dias May 08 '19 at 13:59
  • tried a maxTotal="200" entry? – David May 17 '19 at 07:31
  • hummmm, no. I'll check it out. – Marcelo Dias May 17 '19 at 20:45

1 Answers1

3

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"
Ori Marko
  • 56,308
  • 23
  • 131
  • 233