Apache Tomcat JDBC Connection Pool configuration for Oracle Real Application Cluster(RAC)

No comments

TomcatIn this  article we ‘ll focus  on create high-concurrency connection pool for Apache  Tomcat. You can check a  simple  tomcat JDBC connection pool which added  below. We create a TestDB connection  pool which connects  Oracle  Database  server. The  first configuration  that  we notice “factory”. When tomcat  process  reads “javax.sql.DataSource”  it will automatically configure DBCP  and  the  factory  object  will be  used to create connection pool. So  you have to define factory  object. It’s  required.

There are  many ways  to configure  JDBC connection  in Apache  Tomcat.I’ll focus  one  of  them  at this  post.


Configure  Global  Connection  Pool 


First  you need to add  your  resource  information to  Global resource tab.


Then you have to create a ResourceLink  to make the pool available to the web applications. If  you want  to make  pool available for all web applications  you have to define this  configuration in context.xml file.


Sizing  Connection Pool

We’ll  work  on this sizing  parameters  but  you can get  all of them from the  link.(The Tomcat JDBC Connection Pool)

  • initialSize
  • maxActive
  • maxIdle
  • minIdle
  • timeBetweenEvictionRunsMillis
  • minEvictableIdleTimeMillis
  • validationQuery
  • validationInterval
  • testOnBorrow
  • removeAbandoned
  • removeAbandonedTimeout

It’s  quite  easy  to understand and  configure  this  parameter  but there is some  key points  that we  need to talk about.

initialSize:The  initial number  of  connections  when  connection pool starts.As you can check  it  above we  defined  it  on Global Resource  tab. So  these  connections will start when  you start Tomcat  service.

maxActive:The maximum number of active connections that can be allocated from this pool at the same time.Default  value  is  100. It’s  important  for database  side  when you need to make a capacity  plan for  Database  servers.

minIdle:The  minimum number  of  active  connections  that always  established after  pool created and connection has reached  this  size. In some  cases  it depends  on maxAge parameter. If you set  maxAge  parameter  this can shrink your active  connections .

maxIdle : The maximum number of connections that should be kept in the pool at all times. But  it works  differently when  pool sweeper is enabled. Pool sweeper is a background  process and  manage  and test  idle connections  when pool is active.Pool sweeper has another critical  mission that  responsible for connection leak detection. When pool sweeper  is  enable  it runs  every timeBetweenEvictionRunsMillis miliseconds. If you don’t define this parameters  defaul value  is   5000.

maxIdle is defined;

  • Pool  Sweeper  disabled : (Idle Pool  >  MaxIdle ) : Close Connection which  return the  pool
  • Pool  Sweeper  enabled  : Idle   connection can be grow beyond maxIdle but minEvictableIdleTimeMillis  parameter  will be  important for  this case. Number  of connection can shrink down to minIdle if  connection has been  idle  state  for longer then  minEvictableIdleTimeMillis. This means  that connection will not close  althoug  idle pool is  larger than  maxIdle. If  pool sweeper sets  enable  you should  define maxAge  parameter . Then it’ll check  idle  connections and  will close connection which the  last connection time  longer then maxAge.

Validate Connections

Validate  query is an option that  check database status for  all Database  requests. If you set  validate “validationQuery=”SELECT 1 FROM DUAL””  it means that  query  will be  executed each  java  calls for  database (con = dataSource.getConnection();)

So query validation present a few challenges;

  • It can degrade  database  performance if it calls to often.Validate  query  guarantees   that  connection has been tested before it  gets the connection  however  it will effect  performance of  database and  application. So you should  set “validationInterval”  to minimize  this  effects. If  you set  validationInverval , connection will be validate until next cycle  of  validationInterval.(validationInterval=”34000″ for this case  it  will  validate connection every  34 seconds)
  • And  also if you set validate  query , you should set  testOnBorrow to. This parameter should set true to validate connection and  remove  it  if  it’s dropped  to validate.



Abdurrahim YILDIRIM

Follow me


I'm a System Engineer with extensive experience and administration skills and works for Interbank Card Center Of Turkey.I provide hardware and software support for the following Unix/Linux and Windows platforms.(Oracle Solaris,HP-UX, Linux, IBM-AIX, Windows Servers)
Follow me
facebooktwittergoogle_pluslinkedinby feather

No comments yet.

You must be logged in to post a comment.