tags:

views:

324

answers:

3

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...

+2  A: 

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.

serg10
A: 

See this thread on the spring forums.

The users either ended up switching to c3p0 or adding the testWhileIdle property to the spring configuration:

<prop key="hibernate.dbcp.testWhileIdle">true</prop>

<prop key="hibernate.dbcp.validationQuery">
select * from abc
</prop>
Kevin
Might be worth pointing out to the spring forum posters - that's potentially unsafe validation query. You don't want to run that if there are lots of rows in abc.
serg10
A: 

I would switch to the Oracle Universal Connection Pool library. It's optimized for Oracle JDBC Connections, but also will work with any JDBC driver if you ever switch. It's also JDBC 4.0 compliant and is actually being worked on. C3P0, Proxool, DBCP are all kind of stagnant. It will validate you connection by doing a ping to Oracle rather then a query also, which is much faster.

Oracle UCP

Gandalf
Is the UCP available for 10g?
Rintoul
Yup it works for any database that has a valid JDBC Driver implementation. Just has some special tricks it uses if you happen to be using an Oracle driver.
Gandalf