jakarta-jcs-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Georg Jüttner/inasys GmbH" <g...@inasys.de>
Subject The Double-Checked Locking is Broken Declaration
Date Wed, 18 Dec 2002 11:59:18 GMT

Hello,

can I use JCS in case of either optimizing compilers or shared memory multiprocessors?

In the JCS documentation "Using JCS: Some basics for the web" the example
class BookVObjManager uses the Double-checked locking idiom.

This idiom is widely cited and used as an efficient method for implementing
lazy initialization - but the references cited below show, that the
Double-Checked Locking idiom does not work in case of either optimizing
compilers or shared memory multiprocessors.

Is this idiom used in JCS internally, too?

Many thanks,
Georg Juttner


References:

http://developer.java.sun.com/developer/technicalArticles/Programming/singletons
http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html


Example for the Double-checked locking idiom:

// Double-checked locking -- don't use
public static MySingleton getInstance() {
 if (_instance==null) {
   synchronized (MySingleton.class) {
     if (_instance==null) {
        _instance = new MySingleton();
     }
   }
 }
 return _instance;
}


|   inasys GmbH               |   +49-228-5205-0 (fon)
|   Am Propsthof 76           |   +49-228-5205-100 (fax)
|   D-53121 Bonn              |   http://www.inasys.de
|
|   Geschäftsführer: Ralf Schuster
|   Handelsregister Bonn HRB 3994
|   Ust-IDNr. DE 122 120 637




Mime
View raw message