db connections  
Author Message
Big Jim





PostPosted: 2004-12-18 6:09:00 Top

java-programmer, db connections Guys,

In a a stateful session bean I'm looking up a data source that wraps a
connection pool and using it to retrieve a connection.
How do I return the connection to the pool when I'm done? Is conn.close()
the right thing to do here?

If I just let it go out of scope I eventually get an exception in the pool
with an "out of resources" error.


 
Ryan Stewart





PostPosted: 2004-12-18 7:24:00 Top

java-programmer >> db connections "Big Jim" <email***@***.com> wrote in message
news:QNIwd.330$email***@***.com...
> Guys,
>
> In a a stateful session bean I'm looking up a data source that wraps a
> connection pool and using it to retrieve a connection.
> How do I return the connection to the pool when I'm done? Is conn.close()
> the right thing to do here?
>
> If I just let it go out of scope I eventually get an exception in the pool
> with an "out of resources" error.
>
Read your connection pool's documentation.


 
Sudsy





PostPosted: 2004-12-18 11:29:00 Top

java-programmer >> db connections Big Jim wrote:
> Guys,
>
> In a a stateful session bean I'm looking up a data source that wraps a
> connection pool and using it to retrieve a connection.
> How do I return the connection to the pool when I'm done? Is conn.close()
> the right thing to do here?

Absoutely right! Closing it releases it back to the pool.
 
 
Ryan Stewart





PostPosted: 2004-12-18 13:51:00 Top

java-programmer >> db connections "Sudsy" <email***@***.com> wrote in message
news:cvNwd.338$email***@***.com...
> Big Jim wrote:
>> Guys,
>>
>> In a a stateful session bean I'm looking up a data source that wraps a
>> connection pool and using it to retrieve a connection.
>> How do I return the connection to the pool when I'm done? Is conn.close()
>> the right thing to do here?
>
> Absoutely right! Closing it releases it back to the pool.
>
Are you sure that's universal? I may be wrong, but I thought I'd read about
pooling implementations in which you'd call something like
connection.release() or even ConnectionPool.dump(connection)


 
 
Sudsy





PostPosted: 2004-12-18 14:06:00 Top

java-programmer >> db connections Ryan Stewart wrote:
> "Sudsy" <email***@***.com> wrote in message
> news:cvNwd.338$email***@***.com...
>
>>Big Jim wrote:
>>
>>>Guys,
>>>
>>>In a a stateful session bean I'm looking up a data source that wraps a
>>>connection pool and using it to retrieve a connection.
>>>How do I return the connection to the pool when I'm done? Is conn.close()
>>>the right thing to do here?
>>
>>Absoutely right! Closing it releases it back to the pool.
>>
>
> Are you sure that's universal? I may be wrong, but I thought I'd read about
> pooling implementations in which you'd call something like
> connection.release() or even ConnectionPool.dump(connection)

A quick trip to the javadocs finds this in javax.sql.PooledConnection:

"When an application closes a connection, it calls the Connection
method close. When connection pooling is being done, the connection
pool manager is notified because it has registered itself as a
ConnectionEventListener object using the ConnectionPool method
addConnectionEventListener. The connection pool manager deactivates
the handle to the PooledConnection object and returns the
PooledConnection object to the pool of connections so that it can
be used again. Thus, when an application closes its connection,
the underlying physical connection is recycled rather than being
closed."

Do all implementations faithfully implement this? Possibly not, if
you've heard about situations where non-standard methods are
required. This is just the way it's /supposed/ to work.
Fair enough?
 
 
Big Jim





PostPosted: 2004-12-18 20:53:00 Top

java-programmer >> db connections Thanks guys,

I'll do some testing with the close to see if I get any resource problems
and if I still do I'll resort to that most dreaded of programmer tactis,
RTFM!

"Sudsy" <email***@***.com> wrote in message
news:aOPwd.352$email***@***.com...
> Ryan Stewart wrote:
> > "Sudsy" <email***@***.com> wrote in message
> > news:cvNwd.338$email***@***.com...
> >
> >>Big Jim wrote:
> >>
> >>>Guys,
> >>>
> >>>In a a stateful session bean I'm looking up a data source that wraps a
> >>>connection pool and using it to retrieve a connection.
> >>>How do I return the connection to the pool when I'm done? Is
conn.close()
> >>>the right thing to do here?
> >>
> >>Absoutely right! Closing it releases it back to the pool.
> >>
> >
> > Are you sure that's universal? I may be wrong, but I thought I'd read
about
> > pooling implementations in which you'd call something like
> > connection.release() or even ConnectionPool.dump(connection)
>
> A quick trip to the javadocs finds this in javax.sql.PooledConnection:
>
> "When an application closes a connection, it calls the Connection
> method close. When connection pooling is being done, the connection
> pool manager is notified because it has registered itself as a
> ConnectionEventListener object using the ConnectionPool method
> addConnectionEventListener. The connection pool manager deactivates
> the handle to the PooledConnection object and returns the
> PooledConnection object to the pool of connections so that it can
> be used again. Thus, when an application closes its connection,
> the underlying physical connection is recycled rather than being
> closed."
>
> Do all implementations faithfully implement this? Possibly not, if
> you've heard about situations where non-standard methods are
> required. This is just the way it's /supposed/ to work.
> Fair enough?