Peter Donald <[EMAIL PROTECTED]> writes:
> 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 ;)
What does everyone else think of this diff from Peter? I'm unsure of
its necessity in this situation.
Index: Torque.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/Torque.java,v
retrieving revision 1.39
diff -u -u -r1.39 Torque.java
--- Torque.java 2001/11/13 01:10:27 1.39
+++ Torque.java 2001/11/14 18:01:10
@@ -401,23 +401,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;
}
/**
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>