commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Zoetebier <john.zoeteb...@transparent.co.nz>
Subject Re: rolback() after con.close() in dbcp?
Date Mon, 15 Dec 2003 06:23:11 GMT
On Mon, 15 Dec 2003 02:25:32 +0100, Marten Lehmann <lehmann@cnm.de> wrote:

> Hello,
>
> is a rollback performed when a connection is returned to the pool (no 
> matter if returned through con.close() or after exceeding the 
> removeAbandondedTimeout)?
>
> I'm afraid of the following scenario:
>
> servlet 1: getConnection() -> returns con 1
> servlet 1, con 1: setAutoCommit(false)
> servlet 1, con 1: performs insert 1
> servlet 1, con 1: con.close() -> returned to connection pool
> servlet 2: getConnection() -> returns con 1 from connection pool
> servlet 2, con 1: performs insert 2
> servlet 2, con 1: commit()
>
> And here comes the question: Before servlet 1 closes con 1 no commit or 
> rollback is performed. When servlet 2 get's the same connection later, 
> is it working with insert 1, which isn't rolled back yet although the 
> connection was closed without a commit(), which means it is committing 
> and insert it hasn't created itself?

 From a client point of view connection pooling is transparent. This means 
that for all practical purposes the connection is gone after calling 
Connection.close().
You have to keep in mind that you must start and finish a transaction 
after getting a connection and before returning to the pool.
Your transaction processing must mot rely on any pooling mechanism.
When the connection is returned to the pool it is actually reset to the 
default state.
This means that whenever you get a connection it is in exactly the same 
state as when you whould have created a connection directly.

-- 
John Zoetebier
Web site: http://www.transparent.co.nz

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