pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chen Huajun <chenhj@cn.fujitsu.com>
To: Florent Guillaume <fg@nuxeo.com>
Cc: Scott Harrington <scotth01@sns-usa.com>
Cc: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
Subject: Re: performance problem of Failover Datasource?
Date: Wed, 26 Dec 2012 19:45:28 +0800
Message-ID: <50DAE358.7090909@cn.fujitsu.com> (raw)
In-Reply-To: <CAF-4BpONOd3s8DA7q855fWrQOGs9HS5tFmFToVvOtAUHu9fvRw@mail.gmail.com>
References: <4DFA5A86.9030301@acm.org>
	<itdn5g$eu7$1@dough.gmane.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>
	<CADK3HH+TLPjrrJ=cQWqZ+0B5o96xR+sTVcvqhcDU4CjyryKG2g@mail.gmail.com>
	<50CA959E.4060603@cn.fujitsu.com>
	<50CB29BD.6090903@cn.fujitsu.com>
	<50CC2279.3090301@cn.fujitsu.com>
	<alpine.WNT.2.00.1212151055200.6544@turks>
	<50CFB362.4080701@cn.fujitsu.com>
	<50D82DD5.5020903@cn.fujitsu.com>
	<alpine.WNT.2.00.1212241433350.5232@corsica>
	<50D9AE15.3000807@cn.fujitsu.com>
	<CAF-4BpONOd3s8DA7q855fWrQOGs9HS5tFmFToVvOtAUHu9fvRw@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>


I got it, thanks!

(2012/12/26 19:17), Florent Guillaume wrote:
> On Tue, Dec 25, 2012 at 2:45 PM, Chen Huajun<chenhj@cn.fujitsu.com>  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<String,HostStatus>  newHostStatusMap = (HashMap<String,
>> HostStatus>) hostStatusCache.clone();
>>    newHostStatusMap.put(hostSpecKey, hostStatus);
>>    hostStatusCache=newHostStatusMap;
>> as:
>>    hostStatusCache=(HashMap<String, HostStatus>) 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



view thread (13+ messages)

Message-ID: <50DAE358.7090909@cn.fujitsu.com>
Permalink:  ../50DAE358.7090909@cn.fujitsu.com/
Also on:    postgresql.org/message-id/50DAE358.7090909@cn.fujitsu.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: chenhj@cn.fujitsu.com, fg@nuxeo.com, scotth01@sns-usa.com
  Subject: Re: performance problem of Failover Datasource?
  In-Reply-To: <50DAE358.7090909@cn.fujitsu.com>
  References: <4DFA5A86.9030301@acm.org> <itdn5g$eu7$1@dough.gmane.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> <CADK3HH+TLPjrrJ=cQWqZ+0B5o96xR+sTVcvqhcDU4CjyryKG2g@mail.gmail.com> <50CA959E.4060603@cn.fujitsu.com> <50CB29BD.6090903@cn.fujitsu.com> <50CC2279.3090301@cn.fujitsu.com> <alpine.WNT.2.00.1212151055200.6544@turks> <50CFB362.4080701@cn.fujitsu.com> <50D82DD5.5020903@cn.fujitsu.com> <alpine.WNT.2.00.1212241433350.5232@corsica> <50D9AE15.3000807@cn.fujitsu.com> <CAF-4BpONOd3s8DA7q855fWrQOGs9HS5tFmFToVvOtAUHu9fvRw@mail.gmail.com> <50DAE358.7090909@cn.fujitsu.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox