Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TnpRl-0006bR-5r for pgsql-jdbc@arkaria.postgresql.org; Wed, 26 Dec 2012 11:46:53 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TnpRk-0008Qy-7D for pgsql-jdbc@arkaria.postgresql.org; Wed, 26 Dec 2012 11:46:52 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TnpRj-0008Qh-DC for pgsql-jdbc@postgresql.org; Wed, 26 Dec 2012 11:46:51 +0000 Received: from [222.73.24.84] (helo=song.cn.fujitsu.com) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TnpRe-0007Bt-HS for pgsql-jdbc@postgresql.org; Wed, 26 Dec 2012 11:46:50 +0000 X-IronPort-AV: E=Sophos;i="4.84,356,1355068800"; d="scan'208";a="6478756" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 26 Dec 2012 19:44:47 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id qBQBkr75024788; Wed, 26 Dec 2012 19:46:53 +0800 Received: from [127.0.0.1] ([10.167.159.99]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2012122619463128-622488 ; Wed, 26 Dec 2012 19:46:31 +0800 Message-ID: <50DAE358.7090909@cn.fujitsu.com> Date: Wed, 26 Dec 2012 19:45:28 +0800 From: Chen Huajun User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ja; rv:1.9.2.28) Gecko/20120306 Lightning/1.0b2 Thunderbird/3.1.20 MIME-Version: 1.0 To: Florent Guillaume CC: Scott Harrington , "pgsql-jdbc@postgresql.org" Subject: Re: performance problem of Failover Datasource? References: <4DFA5A86.9030301@acm.org> <4DFA671F.2050005@acm.org> <4DFA9704.4000209@hogranch.com> <4DFAB403.5010309@acm.org> <4DFAB5B8.5010603@hogranch.com> <4DFAB9E2.4070905@acm.org> <1334056170219-5629626.post@n5.nabble.com> <1355303340886-5736270.post@n5.nabble.com> <50C9B102.2060208@cn.fujitsu.com> <50CA959E.4060603@cn.fujitsu.com> <50CB29BD.6090903@cn.fujitsu.com> <50CC2279.3090301@cn.fujitsu.com> <50CFB362.4080701@cn.fujitsu.com> <50D82DD5.5020903@cn.fujitsu.com> <50D9AE15.3000807@cn.fujitsu.com> In-Reply-To: X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2012/12/26 19:46:31, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2012/12/26 19:46:31, Serialize complete at 2012/12/26 19:46:31 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=UTF-8; format=flowed X-Host-Lookup-Failed: Reverse DNS lookup failed for 222.73.24.84 (failed) X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org I got it, thanks! (2012/12/26 19:17), Florent Guillaume wrote: > On Tue, Dec 25, 2012 at 2:45 PM, Chen Huajun wrote: >> Now ,Could you explain the the detail of following issues? >>> At first glance, there are a couple of issues: >>> >>> 1. Double-Checked Locking in reportHostStatus, which is bad form >> >> I knows a problem of Double-Checked Locking,while used in singleton pattern >> as following. >> >> public static Singleton getInstance() { >> if (instance == null) { >> synchronized (Singleton.class) { >> if (instance == null) { >> instance = new Singleton(); >> } >> } >> } >> return instance; >> } >> >> because JVM would run "instance = new Singleton(); " as that : >> >> mem = allocate(); >> instance = mem; >> ctorSingleton(instance); >> >> Do you think my code has the same problem or just it looks ugly? > > Double-checked locking generally is incorrect, and does not work. It > ONLY works if you're double-checking a volatile variable and using > Java>= 5. > Please read http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html > > >>> 3. No need for 'volatile' if you're also using 'synchronized' >> >> 'synchronized' is only used for write,'volatile' is for read. > > This sentence shows you're confused about synchronization and > multi-threading in Java. > >> It's for performance and is a bit complex.(It may be a excessive design) >> I worry about JVM will optimize the following code >> >> HashMap newHostStatusMap = (HashMap> HostStatus>) hostStatusCache.clone(); >> newHostStatusMap.put(hostSpecKey, hostStatus); >> hostStatusCache=newHostStatusMap; >> as: >> hostStatusCache=(HashMap) hostStatusCache.clone(); >> hostStatusCache.put(hostSpecKey, hostStatus); >> >> do you know if it will happen? > > Of course it can. The JVM is free to reorder a lot of things while > respecting the Java Memory Model. > > All this means you shouldn't try to play games with the JVM, just use > a basic lock or synchronization primitive where you need it. > > Florent > > -- > Florent Guillaume, Director of R&D, Nuxeo > Open Source, Java EE based, Enterprise Content Management (ECM) > http://www.nuxeo.com http://www.nuxeo.org +33 1 40 33 79 87 > > -- Best Regards, Chen Huajun -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc