Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #7092
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | markspace <-@.> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Singleton Pattern |
| Date | Sat, 13 Aug 2011 14:41:55 -0700 |
| Organization | A noiseless patient Spider |
| Lines | 22 |
| Message-ID | <j26r3d$nb8$1@dont-email.me> (permalink) |
| References | <3be6e6cf-fa32-4503-9457-b0a1caef8f29@w11g2000vbp.googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Sat, 13 Aug 2011 21:42:05 +0000 (UTC) |
| Injection-Info | mx04.eternal-september.org; posting-host="XjIWM99mD7Ijfdu600oVPA"; logging-data="23912"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/unSKFRikYmR2489E+FxVmnfr610NWwRM=" |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0 |
| In-Reply-To | <3be6e6cf-fa32-4503-9457-b0a1caef8f29@w11g2000vbp.googlegroups.com> |
| Cancel-Lock | sha1:l7qrqgWplYO0hB4Q45tdQsmot0Y= |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7092 |
Show key headers only | View raw
On 8/13/2011 1:56 PM, vbhavsar@gmail.com wrote:
> The synchronized createInstance() method would eliminate the need to
> do double-checked locking
Nope, it's worse than standard double checked field and therefore
broken. Checking once outside of a synchronization block doesn't do
anything, it's still a read of an unsynchronized field.
That's why singleton patterns are often complicated, they're trying to
do something difficult.
See the comments I added to your snippet below.
> public static Singleton getInstance(){
> if (_instance == null){ // unsafe check
> createInstance();
> }
> return _instance;
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
Singleton Pattern "vbhavsar@gmail.com" <vbhavsar@gmail.com> - 2011-08-13 13:56 -0700
Re: Singleton Pattern markspace <-@.> - 2011-08-13 14:41 -0700
Re: Singleton Pattern Patricia Shanahan <pats@acm.org> - 2011-08-13 14:48 -0700
Re: Singleton Pattern Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-08-13 16:43 -0700
Re: Singleton Pattern Ian <m4r35n357@gmail.com> - 2011-08-15 15:00 +0100
Re: Singleton Pattern Lew <lewbloch@gmail.com> - 2011-08-15 07:56 -0700
Re: Singleton Pattern Patricia Shanahan <pats@acm.org> - 2011-08-15 22:07 -0700
Re: Singleton Pattern Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-08-16 00:09 -0700
Re: Singleton Pattern Patricia Shanahan <pats@acm.org> - 2011-08-16 06:15 -0700
Re: Singleton Pattern Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-08-16 06:57 -0700
Re: Singleton Pattern Patricia Shanahan <pats@acm.org> - 2011-08-16 09:25 -0700
Re: Singleton Pattern Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-08-16 18:10 -0700
Re: Singleton Pattern Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-08-13 20:56 -0400
Re: Singleton Pattern Lew <lewbloch@gmail.com> - 2011-08-13 21:12 -0700
Re: Singleton Pattern Rajeev <rajeev.nospam@gmail.com> - 2011-08-14 06:37 -0700
csiph-web