views:

393

answers:

1

I decided to use DBCP mainly because I was getting timeouts on my database connections. In theory, once you define a "validation query", DBCP will by default run that query on the connection before using it, so you always know the connection is OK.

I set it up two weeks ago and it seemed to work. However, last night I got a timeout exception on a connection.

On my dev machine the code survives a MySQL restart without a problem, so I guess DBCP is doing something.

How should I proceed investigating this? Do you use DBCP for this purpose?

(Just deleted 50 lines or so of more detail, trying to keep the question readable. Let me know if some crucial info is missing).

EDIT: Guess I should have read this question before I started...

A: 

This is not always true. I experienced similar problems, but it turned out to be that DBCP has a default behavior that is not very well documented.

You must set the time between eviction runs to purge idle connections. This can be set on a SharedPoolDataSource object by calling setTimeBetweenEvictionRunsMillis. If this is never set, the default value is negative, and the thread never runs!

Even if idle connections are not purged, shouldn't the validation query run to make sure the connection is still up?
itsadok
Is testOnBorrow() set to true?