Tag Archives: Tomcat

Setting up a connection pool on Apache Tomcat 7.x – Part 2

In my previous blog post, I walked through the steps in setting up a tomcat jdbc connection pool. I created a simple spring MVC application to consume the pool. On start up of tomcat, the pool gets created with 10 idle connections. This number can be changed by setting the maxIdle attribute of the Resource tag in server.xml. The minimum idle connections is 10, even if you set this attribute to a lower value.

After tomcat is started, I can view the idle connections in Oracle Enterprise Manager (OEM). I search sessions on Module = “JDBC Thin Client”. I get to see the 10 idle connections as shown below:

Oracle Enterprise Manager screen of connections

Oracle Enterprise Manager screen of connections

When I shutdown tomcat and re-query for sessions, I will see none – as seen below. The tomcat jdbc connection pool gets cleanly closed upon tomcat shutdown:

Connection pool shutdown

Oracle Enterprise Manager screen of connections

What happens if the oracle database instance becomes un-available after the pool has been setup and the application makes use of the connection pool? We could get a stack trace similar to the one below:

INFO: Initialization processed in 2636 ms
Jul 1, 2013 10:06:31 AM org.apache.naming.NamingContext lookup
WARNING: Unexpected exception resolving reference
java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
	at oracle.jdbc.driver.T4CConnection.logon(
	at oracle.jdbc.driver.PhysicalConnection.(
	at oracle.jdbc.driver.T4CConnection.(
	at oracle.jdbc.driver.T4CDriverExtension.getConnection(
	at oracle.jdbc.driver.OracleDriver.connect(
	at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(
	at org.apache.tomcat.jdbc.pool.PooledConnection.connect(
	at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(
	at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(
	at org.apache.tomcat.jdbc.pool.ConnectionPool.init(
	at org.apache.tomcat.jdbc.pool.ConnectionPool.(
	at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(
	at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(
	at org.apache.tomcat.jdbc.pool.DataSourceFactory.createDataSource(
	at org.apache.tomcat.jdbc.pool.DataSourceFactory.getObjectInstance(
	at org.apache.naming.factory.ResourceFactory.getObjectInstance(
	at javax.naming.spi.NamingManager.getObjectInstance(
	at org.apache.naming.NamingContext.lookup(
	at org.apache.naming.NamingContext.lookup(
	at org.apache.naming.NamingContext.lookup(
	at org.apache.naming.NamingContext.lookup(
	at org.apache.catalina.core.NamingContextListener.addResource(
	at org.apache.catalina.core.NamingContextListener.createNamingContext(
	at org.apache.catalina.core.NamingContextListener.lifecycleEvent(
	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(
	at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(
	at org.apache.catalina.core.StandardServer.startInternal(
	at org.apache.catalina.util.LifecycleBase.start(
	at org.apache.catalina.startup.Catalina.start(
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(
	at java.lang.reflect.Method.invoke(
	at org.apache.catalina.startup.Bootstrap.start(
	at org.apache.catalina.startup.Bootstrap.main(

However, when the oracle database instance gets available, to restore the pool tomcat server needs to be bounced. This would trigger to pool creation and then the application is able to perform its functionality. I’ve included the source code of the HROnline application. It reads a list of employee records from the HR database that comes pre-installed with the Oracle virtual box database application. When connected, the list of employees would appear on the page:

Employee list

HR Online employee list

Click here to download the source code.

1 Comment

Posted by on July 1, 2013 in Open Source


Tags: , , ,