db connections

B

Big Jim

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.
 
R

Ryan Stewart

Big Jim said:
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.
 
S

Sudsy

Big said:
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.
 
R

Ryan Stewart

Sudsy said:
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)
 
S

Sudsy

Ryan said:
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?
 
B

Big Jim

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top