commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Phil Steitz" <phil.ste...@gmail.com>
Subject Re: [DBCP] Getting connections from PoolingDataSource
Date Fri, 11 May 2007 04:19:26 GMT
On 5/10/07, Saeed <sayeed_4932@yahoo.com> wrote:
> my comments are in red.
>
> Tushar Madhukar <tushar.madhukar@gmail.com> wrote:    Hi,
>
> I am using DBCP (PoolingDataSource with GenericObjectPool) for pooling
> database connections.
>
> 1. My web application can have multiple clients accessing connections
> simultaneously. Is PoolingDataSource.getConnection() thread safe or do
> I have to handle synchronization?
> yes, it is thread safe.

Technically, this is only true if the underlying pool's borrowObject
is threadsafe.  If you use commons pool's GenericObjectPool (as dbcp's
BasicDataSource does), this is true.  Also, if you allow multiple
threads to access the connections returned by getConnection, it is up
to you to synchronize access while they are checked out of the pool.
>
> 2. How to release all connections in the pool, when the application closes?
> conn.close();

If conn is a connection returned by getConnection, that will only
return it to the pool.  To close all connections in the pool, you need
to close the pool or datasource itself. BasicDataSource has a close
method that does this.  If you are using PoolingDataSource directly,
you need to hang on to a reference to the pool that you used to create
it and invoke the close method on the pool.

Phil

>
> Thanks
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>
>
>
>
> ---------------------------------
> Ahhh...imagining that irresistible "new car" smell?
>  Check outnew cars at Yahoo! Autos.

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message