Return-Path: X-Original-To: apmail-tomcat-users-archive@www.apache.org Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5678C10958 for ; Thu, 7 Nov 2013 21:11:10 +0000 (UTC) Received: (qmail 52070 invoked by uid 500); 7 Nov 2013 21:11:06 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 51963 invoked by uid 500); 7 Nov 2013 21:11:06 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 51954 invoked by uid 99); 7 Nov 2013 21:11:06 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Nov 2013 21:11:06 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy includes SPF record at spf.trusted-forwarder.org) Received: from [76.96.59.212] (HELO qmta14.westchester.pa.mail.comcast.net) (76.96.59.212) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Nov 2013 21:11:01 +0000 Received: from omta21.westchester.pa.mail.comcast.net ([76.96.62.72]) by qmta14.westchester.pa.mail.comcast.net with comcast id mgE51m0041ZXKqc5ElAgPB; Thu, 07 Nov 2013 21:10:40 +0000 Received: from Christophers-MacBook-Pro.local ([69.143.106.98]) by omta21.westchester.pa.mail.comcast.net with comcast id mlAf1m00i27QCxh3hlAg5P; Thu, 07 Nov 2013 21:10:40 +0000 Message-ID: <527C01D2.2040307@christopherschultz.net> Date: Thu, 07 Nov 2013 16:10:42 -0500 From: Christopher Schultz User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 MIME-Version: 1.0 To: Tomcat Users List Subject: Re: DBCP is Single Threaded References: <527BB9EF.5020809@christopherschultz.net> <527BBC50.10101@apache.org> In-Reply-To: <527BBC50.10101@apache.org> X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20121106; t=1383858640; bh=XJeU0Fj8HwQ9fAfmIXjH9XK0uvHTvkIHtP8SHcAWrms=; h=Received:Received:Message-ID:Date:From:MIME-Version:To:Subject: Content-Type; b=VL0kXavIu8ieX5mPbyQnPCpYMAsizqV1R+WCS4jmgN0AGrKHqxTpiDq0VPrMeih/y rjdM+PpEDpVeYf/DCQyXrlSetN+Izz3e92oi8kUVHDU0vIOZrRySdRRLMVABzvBky2 nTjB3e10qB+/xe0UsdkAQB49wZpvh68/r/jqiYRmmYkd5nl17XZZo7ChgE6EkxReFh 1X0U5TaB71bUUrbIeg3HA0vH00vHR5Gh0lWbHORk/eHI2yzzwyGgyYos1qDJLW4gAg 2ksdw2O+sTKYOHDaJiyJVx4xuCBZvnT1Uj3v2SBpmyqrEgtZ58LRFrB3RUB3SEU+CO u5TLiOPfPbQyA== X-Virus-Checked: Checked by ClamAV on apache.org -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 Mark, On 11/7/13, 11:14 AM, Mark Thomas wrote: > On 07/11/2013 16:03, Christopher Schultz wrote: >> Yogesh, >> >> On 11/7/13, 10:58 AM, yogesh hingmire wrote: >>> While looking to upgrade to tomcat7, i understand the >>> connection pool is a major improvement. I read that >> >>> commons-dbcp is single threaded, in order to be thread safe >>> commons-dbcp locks the entire pool, even during query >>> validation. >> >>> So as i understand, the connection pool will be locked when >>> handing out new connections and other threads which need >>> connections from the pool will wait until they are handed >>> their respective connection? >> >>> Is my understanding right and if anyone could explain this >>> better >> >> That is correct. This is because the checkout method is >> implemented like this (ignore syntax issues, this is psuedocode, >> won't match method signatures, etc.): >> >> public synchronized Connection checkout() { // obtain connection >> by whatever means necessary, // validate the connection, etc. } > > Huh? > > Have you even looked at the source for Commons Pool at any point > in the last 4 years? (Commons Pool being the component that > provides the object pooling used by Commons DBCP). Sorry, I should have said it looks like this (which nobody would be able to comprehend): public /* not synchronized */ Object borrowObject() { synchronized (this) { // register this thread's desire for an object } allocate(); /* note: synchronized method */ for(;;) { synchronized(this) { // check that pool is open } // use a synchronized Latch object if(poolExhausted { synchronized (this) { // take appropriate action } } // use a synchronized Latch object if(got object) return object; else continue; } } So... you're right: it's not one big synchronized method. Instead, it's a mismash of monitor acquisitions and releases, many of which are for "this". Mostly what all that acrobatics yields is the ability to implement a fair thread-queuing system. In a fair thread-queuing system, the effect is that ... all threads are serialized. So if 5 threads need objects from the pool, they will all wait in line. Can you describe the effective difference between my over-simplified description and what is implemented in commons-pool (ignoring thread-fairness, which I'll admit is a very useful feature)? - -chris -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.15 (Darwin) Comment: GPGTools - http://gpgtools.org Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQIcBAEBCAAGBQJSfAHQAAoJEBzwKT+lPKRYk+QP/iu8wIha5rntfSdRZ/HshdMG KohNrU+l7SLXNqNAaI8505YbNusc+jy+PT++FtQj8WfLoViCVMiPPEpnoqsoeuK+ AHkrw2nQYyVDelY+7s/BWtFYuUaupLAeg2O8Hk+d/Dr18Toh3ZOq3+PStoCeMJX8 HjlkgHdQGmyQ7qjjTHtykidC5V8x16uTjSWEUyVFauWEM5ZkpC9dXXPE0rPrDXWi cWgUG9QxTztGcEsMLinapuwueldTDCP9ZHOadi85tk0OE7efr8E72XTmfhYKUIy5 ZHjt2obJeyJinOXZq2VAy8iOxMPM7SrS7E2vFIkjAiP+/f6MX8emAGy1lZ76ajb7 6w4kZuXdFlCJhpDc70ZwX90Xh4uusY2msmRFJQr+JOPZ70b3vpX1nYagsn7sPZ8G n1R+9vtNgRRjivusuYXJjUxdWZOZudMAEKAjCrW/vwXxJICbGu1qnDvnqBlsVtjZ 23wc3IqfNlsvTYLKHAsgdjYv7zZiRmmzE4BPqLcuyBn7FkSZ/9dgUTfZE8SDXrTG 2RAJdL3nmqgAxOXHzVDx7i4OmC7JLgdgtQ7pNyy7B8N/xUxLeqnuJRgFnQcaLc4C jGDhseWmIdUx1ZxJAOJJzV+SPV6wy/HlQoRhxccb99LSWpneptqhizvcmfhtHBYk a+/0l/3CdT0Y9SIRw73A =OBJ4 -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org For additional commands, e-mail: users-help@tomcat.apache.org