title: JVM Datasource tuning idle database connection in the connection pool for tomEE
body: <p>I am trying to figure out if my Datasource definition is the root cause for an issue we are having. Our application stack in AWS has several TomEE machines running together behind and ELB. Randomly machines with retain idle connections to the database and not terminate. </p>
  
  <p>I am wanting to know what we can do to better setup our connections and reaping of connections. Our application does have a moderate number of requests /sec.</p>
  
  <p>Here is our Tomee.xml file. </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;tomee&gt;
  &lt;!-- see http://tomee.apache.org/containers-and-resources.html --&gt;
  &lt;!-- Datasources for Prod --&gt;   
     &lt;Resource id="DBWPC" type="javax.sql.DataSource"&gt;
        DataSourceCreator tomcat
        JdbcDriver oracle.jdbc.OracleDriver
        JdbcUrl jdbc:oracle:thin:@x.x.com:1521:service
        UserName xxxxx   
        Password xxxx
        jmxEnabled true
        InitialSize 5
        MaxActive 20
        MaxIdle 20
        MinIdle 0
        MaxWait -1
        ValidationQuery SELECT 1 FROM DUAL
        PoolPreparedStatements true
        MaxOpenPreparedStatements 0
        TestWhileIdle true
        timeBetweenEvictionRunsMillis 180000
        JtaManaged true      
     &lt;/Resource&gt;
   &lt;!-- Standard JMS Setup for NON-SERVER **** START **** --&gt;
   &lt;Resource id="PrimaryJMSRA" type="ActiveMQResourceAdapter"&gt;
              BrokerXmlConfig=
            ServerUrl = tcp://x.x.com:61616
    &lt;/Resource&gt;
    &lt;Resource id="JmsConnectionFactory" type="javax.jms.ConnectionFactory"&gt;
              ResourceAdapter = PrimaryJMSRA
      &lt;/Resource&gt;
   &lt;Container id="JmsMdbContainer" ctype="MESSAGE"&gt;
      ResourceAdapter = PrimaryJMSRA
  &lt;/Container&gt;
  &lt;Container id="wpcStatelessContainer" type="STATELESS"&gt;
   accessTimeout = 30 seconds
   callbackThreads = 5
   closeTimeout = 5 minutes
   garbageCollection = false
   idleTimeout = 0 minutes
   maxAge = 0 hours
   maxAgeOffset = -1
   maxSize = 5000
   minSize = 20
   replaceAged = true
   replaceFlushed = false
   strictPooling = false
   sweepInterval = 5 minutes
   &lt;/Container&gt;
   &lt;Container id="wpcSingletonContainer" type="SINGLETON"&gt;
      accessTimeout = 30 seconds
  &lt;/Container&gt;
  </code></pre>
  
  <p></p>