On Mon, 22 Oct 2001 11:04, Daniel Rall wrote:
> Peter Donald <[EMAIL PROTECTED]> writes:
> > I noticed you were using double checked locking in one class.
> > Unfortunately due to javas memory model this is not an approach that
> > works. In short DCL is a broken pattern and if you want the full
> > commentry there was discussion of this approach on the Javaworld site (do
> > a search for Brian Goetz + DCL).
> >
> > The probelm essentially comes down to java allowing extensive operation
> > reordering that could result in the value being assigned to value before
> > it is fully initialized and thus a check for null would pass but the
> > actual object would not be ready for use. Heres a patch to correct this
>
> We're aware of DCL issues.  Patch was not attached, and I'm not sure
> which class you're referring to.

Ooops - my excuse is that I hadn't yet had my daily dose of caffeine ... err 
coffee ;)

-- 
Cheers,

Pete

-----------------------------------------------------------
    If your life passes before your eyes when you die, 
 does that include the part where your life passes before 
                        your eyes?
-----------------------------------------------------------
Index: Torque.java
===================================================================
RCS file: /home/cvspublic/jakarta-turbine-torque/src/java/org/apache/torque/Torque.java,v
retrieving revision 1.18
diff -u -r1.18 Torque.java
--- Torque.java	2001/10/21 21:06:52	1.18
+++ Torque.java	2001/10/22 00:24:12
@@ -296,23 +296,19 @@
             }
         }
 
-        // Quick (non-sync) check for the map we want.
-        DatabaseMap map = (DatabaseMap) dbMaps.get(name);
-        if (map == null)
+        //DCL is broken !!!!!!!!!!!!!!!
+        //We can not use it in a multithreaded environment.
+        //Thus we are forced to go through synchronizaed section
+        synchronized (dbMaps)
         {
-            // Map not there...
-            synchronized (dbMaps)
+            DatabaseMap map = (DatabaseMap) dbMaps.get(name);
+            if (map == null)
             {
-                // ... sync and look again to avoid race condition.
-                map = (DatabaseMap) dbMaps.get(name);
-                if (map == null)
-                {
-                    // Still not there.  Create and add.
-                    map = initDatabaseMap(name);
-                }
+                // Still not there.  Create and add.
+                map = initDatabaseMap(name);
             }
+            return map;
         }
-        return map;
     }
 
     /**
@@ -334,8 +330,7 @@
         try
         {
             DB db = DBFactory.create(getDatabaseProperty(name, "driver"));
-            for (int i = 0; i < IDGeneratorFactory.ID_GENERATOR_METHODS.length;
-                 i++)
+            for (int i = 0; i < IDGeneratorFactory.ID_GENERATOR_METHODS.length; i++)
             {
                 map.addIdGenerator(IDGeneratorFactory.ID_GENERATOR_METHODS[i],
                                    IDGeneratorFactory.create(db));
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to