0
votes

I have configured Apache DBCP2 JNDI datasource in Apache Tomcat 8.5.16. My Resource tag in context.xml looks as below.

<Resource auth="Container"
    type="javax.sql.DataSource" 
    driverClassName="com.mysql.cj.jdbc.Driver"
    url="jdbc:mysql://localhost:3306/mydb?autoReconnect=true&amp;useSSL=false"
    username="root"
    password="mypassword"
    name="jdbc/myDS"
    initialSize="5"
    minIdle="5" 
    maxIdle="10"
    maxTotal="20"
    testOnCreate="true"
    testOnBorrow="true" 
    testOnReturn="true"
    testWhileIdle="true"
    validationQuery="SELECT 1 from dual"
    validationQueryTimeout="60"
    timeBetweenEvictionRunsMillis="180000"
    numTestsPerEvictionRun="10"
    softMinEvictableIdleTimeMillis="150000"
    maxConnLifetimeMillis="300000"
    logAbandoned="true"
    removeAbandonedOnBorrow="true"
    removeAbandonedOnMaintenance="true" 
    removeAbandonedTimeout="60"
    maxWaitMillis="60000" />

My questions are:

  1. I started the tomcat (I haven't deployed any application on tomcat yet). I opened MYSQL client terminal, logged in as root. Now when I run command show processlist, I am seeing 31 connections. 1 from MYSQL client terminal and 30 from tomcat. Why DBCP2 has acquired 30 connections when my maxTotal is 20? No, one else is using MYSQL other than tomcat and MYSQL client terminal.
  2. Since I haven't deployed any application on tomcat to use JNDI datasource all my connections from DBCP2 are Idle. timeBetweenEvictionRunsMillis="180000" is not removing these idle connections.
  3. When I remove minIdle="5". Then after 180000 millis all 30 MYSQL connections gets removed from connection pool and connection pool size becomes zero.

Help me understand this behavior. Thanks is advance.

1

1 Answers

0
votes

Sorry everyone. It's was mistake in my understanding. Tomcat 8.5.16 that I was using already has 6 applications in webapps directory(ROOT, docs, examples, host-manager, manager, etc). Since, I created Apache DBCP2 JNDI datasource in context.xml in tomcat's conf directory, Tomcat has created 6 connection pools having initialSize="5" for each application in webapps directory. I need to revisit my JNDI datasource configuration so that I can restrict it to be used by 1 application.
Thanks everyone for passing by.