On 5/10/07, Tushar Madhukar <[EMAIL PROTECTED]> wrote:
Phil/Sayeed, appreciate your help.

Thanks.

On 5/11/07, Phil Steitz <[EMAIL PROTECTED]> wrote:
> On 5/10/07, Saeed <[EMAIL PROTECTED]> wrote:
> > my comments are in red.
> >
> > Tushar Madhukar <[EMAIL PROTECTED]> 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.
>
One more point on this.  While in many cases, gc will take care of
this, to be certain that all connections that you open via the pool
get promptly closed, you need to return them all to the pool before
closing the pool, since BasicDataSource.close only closes the
connections that have been returned to the pool.

Phil

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to