Return-Path: Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 42309 invoked from network); 6 Mar 2003 05:41:32 -0000 Received: from ext-nj2gw-1.online-age.net (216.35.73.163) by daedalus.apache.org with SMTP; 6 Mar 2003 05:41:32 -0000 Received: from int-nj2gw-2.online-age.net (int-nj2gw-2.online-age.net [3.159.236.66]) by ext-nj2gw-1.online-age.net (8.12.3/8.9.1/990426-RLH) with ESMTP id h265ff0g018764 for ; Thu, 6 Mar 2003 00:41:41 -0500 (EST) Received: from kans015cercge.erc.gecapital.com (localhost [127.0.0.1]) by int-nj2gw-2.online-age.net (8.12.3/8.12.3/990426-RLH) with ESMTP id h265fYEI018135 for ; Thu, 6 Mar 2003 00:41:35 -0500 (EST) Received: by ercmailhost.erc.gecapital.com with Internet Mail Service (5.5.2656.59) id ; Wed, 5 Mar 2003 23:41:34 -0600 Message-ID: From: Gaurav.Goyal@ercgroup.com To: commons-user@jakarta.apache.org Subject: DBCP multithreading scenario Date: Wed, 5 Mar 2003 23:41:33 -0600 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2656.59) Content-Type: text/plain; charset="iso-8859-1" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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 passivated. 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?