Exceeding Maximum Idle Time in Java Web Application with Oracle DB

apache-commons-dbcp, java, oracle

Solution

Try setting the `testWhileIdle` property to `true` when configuring your datasource. You'll also need a test query - for Oracle, something like `select 1 from dual` will suffice.

This will prompt dbcp to nudge any idle connections to keep them fresh.

You can also consider evicting connections that become idle if you don't mind recreating them once they are needed later. Have look at the documentation describing the configuration options for the `minEvictableIdleTimeMillis`, `timeBetweenEvictionRunsMillis` and `maxIdle` / `minIdle` properties.

Problem

I have a Java web application connecting to an Oracle database running on another machine (not sure if this is relevant or not). I am using DBCP for connection pooling. The web application is running in JBoss 4.2.2 and we are defining our datasource as a bean in Spring. We are using Hibernate for ORM. We are getting errors occasionally like so: "ORA-02396: exceeded maximum idle time, please connect again". I have tried adding properties to our DBCP BasicDataSource called "removeAbandoned" (true) and "removeAbandondedTimeout" (120) to no avail. Any help would be appreciated. If I need to provide more information, please let me know - I'm not all that knowledgeable about the inner workings of connection pooling, etc...

Original source