Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.posted.palinacquisition!news.posted.palinacquisition.POSTED!not-for-mail NNTP-Posting-Date: Tue, 16 Aug 2011 20:10:24 -0500 Date: Tue, 16 Aug 2011 18:10:24 -0700 From: Peter Duniho User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.18) Gecko/20110616 Thunderbird/3.1.11 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Singleton Pattern References: <3be6e6cf-fa32-4503-9457-b0a1caef8f29@w11g2000vbp.googlegroups.com> <4o6dnfZWI_mOZtTTnZ2dnUVZ_oqdnZ2d@earthlink.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Lines: 27 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 50.46.118.188 X-Trace: sv3-2OI8N5cZy3HJLBTrWUUNfJIMs9dS3ObnMGYVLdYc+Y4b9p9bPCS/JdcPTRL1lS4o7u0pECMDH92V9AL!lg8DZ5HvDW9t6kfEbNPP8hxiS9ZaaglAilbyOQ5hYtYnTtX20kUvH45Nxvxpj1drB/kEt30ZkADs!NvpZBPL+PwmXNFyuUeZPGuNqZ4hETz30VxCluLvzVZE= X-Complaints-To: abuse@iinet.com X-DMCA-Complaints-To: abuse@iinet.com 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: 3014 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7150 On 8/16/11 9:25 AM, Patricia Shanahan wrote: > On 8/16/2011 6:57 AM, Peter Duniho wrote: > .... >> Or looked at another way: if someone has messed up the class design such >> that a singleton class is used even though the singleton instance is >> never actually needed, I'm not sure I trust that person to correctly >> implement even the basic explicit singleton initialization >> synchronization code. Even in that case, better to suffer the potential >> performance hit than to allow them to try to get the explicit >> initialization right. > .... > > I'm not convinced the method synchronization approach is bad from a > performance point of view. I've never seen a getInstance method as a > heavy hitter in a profile. I suspect that almost always the > synchronization will be uncontended. [...] Nothing I wrote should be construed as suggesting a _performance_ problem with an explicitly synchronized initialization. My point is simply that there's no reason to do it that way when the JVM will handle all the heavy lifting for you, with trivial syntax. The only performance hit any of my posts mentioned would be the one that comes from initializing a singleton during a program's execution where it's never used. Pete