Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

Search: 

  Tutorial: Double-checked locking is still broken

Double-checked locking is still broken

Tutorial Details:

Newsflash: Double-checked locking is still broken
Newsflash: Double-checked locking is still broken
By: By Tony Sintes
Tony responds to a reader's suggestion about synchronization
April 12, 2002
In " Singletons with Needles and Thread ," you declare the getInstance() method in the Singleton class as synchronized. The drawback to this approach: the getInstance() call is synchronized even if the Singleton exists -- thus introducing unneeded overhead.
I suggest the following as a better approach:
public class Singleton {
private static Singleton instance;
public static Singleton getInstance() {
if (null == instance) {
synchronized(Singleton.class) {
if (null == instance) {
instance = new Singleton();
}
}
}
return instance;
}
}
I'll keep this short: Double-checked locking is still broken. Please read:
" The 'Double-Checked Locking Is Broken' Declaration ," David Bacon, et al.
" Double-Checked Locking: Clever, but Broken ," Brian Goetz ( JavaWorld, February 2001)
" Warning! Threading in a Multiprocessor World ," Allen Holub ( JavaWorld, February 2001)
" Can Double-Checked Locking Be Fixed? ," Brian Goetz ( JavaWorld, May 2001)
" Can ThreadLocal Solve the Double-Checked Locking Problem? ," Brian Goetz ( JavaWorld, November 2001)
"Letters to the Editor," ( JavaWorld ):
March 2001
June 2001
July 2001
November 2001
Also, consider this alternative:
public class Singleton {
public final static Singleton INSTANCE = new Singleton();
private Singleton() {}
}
This page formated for crawlers and browsers that don't support scripts and tables.
Home
EZone


 

Read Tutorial at: Click here to view the tutorial

Rate Tutorial:
Double-checked locking is still broken

View Tutorial:
Double-checked locking is still broken

Related Tutorials:

Displaying 1 - 50 of about 292 Related Tutorials.

Locking Issues
Locking Issues, Internal Locking Methods, External Locking Locking Issues       ... for table contents by using Locking : Internal Locking can be performed in the MySQL
 
MySQL Transactional and Locking Statements
MySQL Transactional and Locking Statements, Start Transaction  Commit... and Locking Statements         ... The general syntax for locking and unlocking the tables is: LOCK TABLES tbl_name
 
SUSE Linux 10.1 Beta 6 has been released
'Agama Lizard' beta 6. Beta 6 has still some rough edges and I will not advise to put... afterwards. 2. The partitioner is broken in some cases (Bug 151947). which might...; o creates double or totally obscure entries within the fstab of the system
 
Jupiter
development, and still in an experimental state. The design of Jupiter involves
 
Code Collaborator
still get reports and metrics. Major Features of CodeCollaborator With 6000+ active... or after check-in. Before local file changes are checked into version control, upload them for review with a single click. Or upload already checked
 
Catching Exception using c: catch and c:set
have written some code which you think that it can invoke a error, and still you... are trying to divide double x to String y. The result is well known.<br> 
 
JSTL c:catch with c:if
that it can invoke a error, and still you are confident that you can recover from...="c" uri="http://java.sun.com/jstl/core"%> <% Double db= (Double) (Math.random() * 20); pageContext.setAttribute("random", db
 
C and C++ books-page1
is no longer in print, it's content is still very relevant today. The C language is still popular, particularly for open source software and embedded programming
 
Catching Exception usin c: catch
some code which you think that it can invoke a error, and still you are confident
 
JSTL
that it can invoke a error, and still you are confident that you can recover
 
Sources of GPS Error
and development work is still going on to develop more and more accurate systems, it would
 
Features of Servlet 2.5
the features of Servlet 2.5. Still most of the popular containers like Tomcat 5.5
 
Open Source Outlook
are still locked into their propietary, vertically locked down world; we need..., are still struggling to catch up on the features of Office 97
 
The Ubuntu Linux 6.04 Alpha 3 has been released
. * The powerpc live CD is still pretty broken, due (I think) to unionfs bugs. * OEM installation is broken, since it hasn't been fixed up to cope.... * Installation on non-networked machines now works properly again (broken in Flight
 
Foresight Linux 0.9.4 MR2 is released now
. Seems to be working well, though still needs a little work to make everything work... to ship it. NetworkManager bug fixed I have been plagued with a broken
 
SUSE Linux 10.1 Beta 5 has been released
out most of the rough edges of beta4, but I still do not advise to put it on any production system! Beta5 is still for the adventurous experts... issues.. Beta5 is still for the adventurous experts and not for anybody without
 
Car Theft Preventions using Vehicle Tracking System
the power of the country but like double-edged sward this development in other... figure of total cases of the year is still awaiting, because the above figure... such as centralized locking system, in which the car is locked or unlocked by its remote
 
Hibernate Training
Examples: Using Transaction API Locking Examples Examples: Implementing optimistic locking with versioning Day 3
 
Hibernate 3.1.2 Released
be serialized after session is closed * [HHH-1398] - extends and entity-names broken with mapping-level package attribute * [HHH-1407] - return-join broken
 
Hibernate 3.1.3 Released
seems to be broken in 3.1.x * [HHH-1445] - SchemaUpdate closes shared ConnectionProvider * [HHH-1453] - Broken exception handling in NullableType
 
MySQL Training ? Online Free MySQL Training
Locking Issues MySQL can manage the contention for table contents by using Internal and External Locking. Internal Locking can be performed... by multiple threads. External locking is performed when server and other programs
 
Open Source Document Management
, distributed caching and locking. This needs to be built using the latest state... unlimited storage and user access 3. Yet still giving you complete control over... Management Suite 5.0 embrace simplicity and still deliver solid document and file
 
Open Source Databases
the InnoDB transaction storage engine that includes row-level locking. Coming..., and defensive posturing And even so you might still be wondering what it all
 
Submit Tutorials - Submitting Tutorials at RoseIndia.net
. If this agreement is broken, RoseIndia.net has the authority to remove your tutorial
 
Border Example
them. You could add the border in one massive statement, but here it's broken down
 
Linux Open Source
that a firewall is not necessary. But Windows cannot, and Mac OS X is still an unknown... that it's still very, very hard to get Linux unless you're a technical user. Novell... and naturally Massachusetts is still going strong. The ODF Alliance certainly
 
Tutorials - Java Server Pages Technology
of the architecture is broken up into multiple tiers. In this case... evolved into what it is today and it is still evolving
 
Servlet Tutorials Links
for all entries during that week. For simplicity the mailing lists is not broken out.... The megacorp ISPs and Hosting companies still don't offer servlets, though
 
Open Source Intelligence
on the fourth plane were alerted to the crisis while still in the air. They fought... direct action. It gave proof that our national security establishment is broken
 
Open Source Movement
broken up, many now view Linux as the only long-term challenge to the all... of it) while still at UC Berkeley around 2000. I did some work (actually my students
 
Tutorials - Java Server Pages Technology
of the architecture is broken up into multiple tiers. In this case... evolved into what it is today and it is still evolving
 
Open Source Movement
broken up, many now view Linux as the only long-term challenge to the all... of it) while still at UC Berkeley around 2000. I did some work (actually my students
 
JDO Implementations
in your code, you can define timers, locking policies, queries, fetch policies... b.) Locking managed by Speedo itself or by the database (clustering support
 
Welcome to the MySQL Tutorials
; Locking Issues MySQL can manage the contention for table contents by using Internal and External Locking. Internal Locking can... content by multiple threads. External locking is performed when server
 
MySQL Tutorial - SQL Tutorials
; Locking Issues MySQL can manage the contention for table contents by using Internal and External Locking. Internal Locking can... content by multiple threads. External locking is performed when server
 
Open Source projects
commit a broken build; that new contributors should be able to easily install... still learning new things ourselves. Another topic in our world today... are running a site on a very old version of Slash pre-2.2.6, we still recommend that you
 
Linux Books
all still apply, although we have adding and expanded them. In addition, we... cleaning, fixing broken windows, and other such things.    ... detail, and always supported with a readily usable example. The work is still
 
Colocation Hosting
with dedicated power and locking doors
 
What is Persistence Framework?
. SimpleORM takes great care with database semantics. Locking, quality... database integrity. Optimistic locks are used for inter-transaction locking
 
Breaking the String into Words
string has been broken into words based on the blank spaces between the words
 
Types of Graphs and Charts
; we have to show that how this whole quantity is broken into parts. The whole
 
Struts 2.0.3 Released
of Double in the request parameters # [WW-1583] - Linked Autocompleter not working... # [WW-1642] - Fileupload broken # [WW-1646] - TabbedPanel is not assigning "id
 
Open Source Download Manager
managers can help download very large files by resuming broken downloads
 
rPath Linux 0.99.4 is released
* libgnomeui fixed to remove broken overrides on componentization for libraries
 
Fedora Core 5 Test 2 Released
, as many parts are likely to be broken and the rate of change is rapid. http
 
Spyware: What It Is and How to Combat It
. Spyware can be broken down into two different categories, surveillance... Double your income! Internet marketing expert, Dean Phillips will teach you how to double your income, starting today...Guaranteed! For details just visit
 
BeleniX 0.4.2 has been released now
with the startkde and startxfce scripts 7.  Harddisk install was broken... segment.  This reduces double-caching overhead. Since    ... is double cached which is about 6% of the total. Thus this improves effectiveness
 
Old and New Vector Methods
, the DefaultListModel still uses the old methods, so if you are using a JList, you... this, but still and interesting omission. Replacements for old methods
 
Change Listener
the getValueIsAdjusting() method to see if the user is still moving the knob and hasn't released...() is true if the user is still has the mouse button down, and false if the user has
 
Source Mage GNU/Linux 0.9.6 is available now
a vital step or do things in the wrong order - you can still override... or do things in the wrong order - you can still override dependencies if you really
 
Site navigation
 

 

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2006. All rights reserved.