Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!nx01.iad01.newshosting.com!newshosting.com!69.16.185.16.MISMATCH!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!news2.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Sat, 13 Aug 2011 16:48:34 -0500 Date: Sat, 13 Aug 2011 14:48:31 -0700 From: Patricia Shanahan User-Agent: Mozilla/5.0 (Windows NT 5.2; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Singleton Pattern References: <3be6e6cf-fa32-4503-9457-b0a1caef8f29@w11g2000vbp.googlegroups.com> In-Reply-To: <3be6e6cf-fa32-4503-9457-b0a1caef8f29@w11g2000vbp.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <042dnWOC1_6vbNvTnZ2dnUVZ_hydnZ2d@earthlink.com> Lines: 29 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 70.230.203.65 X-Trace: sv3-oaVBqB1mpGKkAXCwLgrR9Gz6fY/vNQyXpe1sPy7DrDDinZcyuOUDrEMJ+jIQx9gNzpyTKW1jlPuC2XV!v7jkY0NZgsZyJA102Pw9JWP/Wyj2pCf9n3TjOHyHTZ1v7hEGvMqZHfVXPH4RpHxiK5QlmWVzMfsc!ob0sjihc/3MNu+/GNg+0ZaSLvP/NL+Ej10Q4WP0+kAebdQ== X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 1950 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7093 On 8/13/2011 1:56 PM, vbhavsar@gmail.com wrote: ... > public class Singleton { > > private static Singleton _instance; > private Singleton(){} > > private synchronized static void createInstance(){ > _instance = new Singleton(); > } > > public static Singleton getInstance(){ > if (_instance == null){ > createInstance(); > } > return _instance; > } > } ... > Anyone see any issues with this? Suppose thread A calls getInstance, sees _instance to be null, calls createInstance, and some time later thread B calls getInstance and also sees _instance to be null. Isn't B going to go ahead and re-initialize _instance? If you do not think that is possible, please explain why not. Patricia