You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Tony Seebregts <to...@cibecs.com> on 2005/08/15 15:59:23 UTC

Re. PooledConnection being closed

Ok, thanks Knut - my misunderstanding. 

I understood the ConnectionPoolDataSource as merely facilitating connection pooling. If it manages the actual pooling though, is there any point in handling the ConnectionEvents ? Other than for monitoring/interest ...

regards

Tony Seebregts



>-----Original Message-----
>From: Knut Anders Hatlen [mailto:Knut.Hatlen@Sun.COM] 
>Sent: Monday, August 15, 2005 1:41 PM
>To: Derby Discussion
>Subject: Re: PooledConnection being closed
>
>
>Well, the point with pooled connections is that you use
>getConnection() and close() as with ordinary connections, but the
>underlying physical connection is kept open. The Connection object
>returned by getConnection() is a logical connection, and you cannot
>use it after it is closed. If you call getConnection() again, you will
>get a new logical connection, and therefore a new Connection
>object. However, the new logical connection might still use the same
>physical connection.
>
> -- Knut Anders 



Re: Re. PooledConnection being closed

Posted by Knut Anders Hatlen <Kn...@Sun.COM>.
Tony Seebregts <to...@cibecs.com> writes:

> Ok, thanks Knut - my misunderstanding.
>
> I understood the ConnectionPoolDataSource as merely facilitating
> connection pooling. If it manages the actual pooling though, is
> there any point in handling the ConnectionEvents ? Other than for
> monitoring/interest ...

The ConnectionPoolDataSource doesn't manage the connection pool. It is
just an instrument which is used by a connection pool manager. A
ConnectionPoolDataSource can create PooledConnection objects, but
since each PooledConnection can have only one open Connection object
at a time, you'll probably need more than one PooledConnection object,
and the need for a pool manager emerges.

A typical connection pool manager has a getConnection() method which
checks whether there is an unused PooledConnection in the pool. If
there is one, PooledConnection.getConnection() is called, otherwise a
new PooledConnection is created and its getConnection() is called. In
addition the manager has to make sure that the pool doesn't become too
big, that invalid PooledConnection objects are removed from the pool,
etc. That's where the ConnectionEvent handlers come into use. The
connectionClosed() method marks a PooledConnection as unused, and
removes it from the pool if the pool has become too big. The
connectionErrorOccurred() removes an invalid PooledConnection from the
pool.

-- 
Knut Anders