commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject DBCP multithreading scenario
Date Thu, 06 Mar 2003 05:41:33 GMT
I was just going through the DBCP source code and trying to think what could
be causing some of the db connection problems that we are seeing in our
application. From the behaviour that we have seen, I'm almost certain that
somehow the pool has two references to the same connection.
I think if something like this happenned, then its possible that the pool
may have two references to a connection.

Consider two threads: Thread 1 and Thread 2.

Thread 2 wants to return a connection.
So returnObject of GenericObjectPool is called.
There is a portion of returnObject before the synchronized call and there is
one after the synchronized call.
Let us say, before the call from Thread 2 reaches the synchronized portion
we have determined that "success = true" and so the connection is
Now just before the synchronized portion of Thread 2 could start, Thread 1
asks for a connection and so the borrowObject method is called. This locks
the GenericObjectPool and so Thread2 has to wait while Thread 1 is
executing. Since thread 2 already passivated its connection, its available
for Thread 1 to borrow.
Now in this case, the same connection could be returned to Thread 1 and also
added again to the pool because of Thread 2.

So is this right or am I missing something?

View raw message