Connection Pool

Started by Jonathan Tripathyover 15 years ago2 messagesgeneral
Jump to latest
#1Jonathan Tripathy
jonnyt@abpni.co.uk

Hi Everyone,

I'm trying to work with connection pools. The example I'm looking at is
lockated here:

http://www.developer.com/img/2009/11/Listing1_ConnectionPoolClass.html

You will notice that the getConnectionFromPool method does not implement
any blocking, and only returns null.

I would like my application to try and get a connection from the pool,
and if there are none free, wait until either one is free or time is up.

What is the best way to do this? Would creating a wrapper method work?
This wrapper method would check for null, and if so, execute a while
loop until a connection is returned. Also, would this wrapper method
need to be synchronised (remembering that multiple threads may be trying
to get a connection)?

Thanks

Jonny

#2Craig Ringer
craig@2ndquadrant.com
In reply to: Jonathan Tripathy (#1)
Re: Connection Pool

On 11/02/2010 01:42 AM, Jonathan Tripathy wrote:

I would like my application to try and get a connection from the pool,
and if there are none free, wait until either one is free or time is up.

Rather than rolling your own connection pool, consider using one of the
well-established existing ones like DBCP. Alternately, you can use the
pooling DataSource offered by the PostgreSQL driver, though it's pretty
minimal as well.

http://commons.apache.org/dbcp/

Alternately you could use server-side pooling with PgPool-II.

--
Craig Ringer