Hi John,
John Freeborg wrote:
> Forgive me - I don't want to seem critical here - I'm pretty excited
> about using OJB and the potential it has!
>
> However, I've read in a number of places that double checked locking
> (DCL) isn't really safe in Java:
>
> http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-double.html
> http://www.javaworld.com/javaworld/jw-05-2001/jw-0525-double.html
> http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html
>
> I've noticed that a few spots in OJB sort of use DCL, but don't really
> do full DCL as there is no second check after the synchronized()
> statement (see comment):
I'm well aware of the Java DCL problems. Even if our code had the second
check there is no real protection.
Of course we might use synchronized on the method level, but that would
decrease performance for the "normal" flow, where the singleton instance
is already present.
All the classes you mention don't have state that could be corrupted by
having duplicate instances.
in places where object state could be corrupted we always use proper
synchronization on method level.
If you find any places where this is not the case it is a bug and needs
to be fixed!
cu,
Thomas
>
> public static LockManager getLockManager()
> {
> if (LOCKMAN == null)
> {
> synchronized (LockManager.class)
> {
> // This would be DCL, but the code doesn't have this
> second check
> // if (LOCKMAN == null)
> LOCKMAN = createNewLockManager();
> }
> }
> return LOCKMAN;
> }
>
> LockMapFactory, SequenceManagerFactory, PersistentFieldFactory,
> ObjectCacheFactory seem to use this same style of singleton creation.
>
> If folks believe otherwise on DCL, I'd like to know as I try to follow
> that sort of stuff. Otherwise it is probably safer to simply make these
> methods synchronized.
>
> I worry about this as I'm planning on using OJB inside a servlet
> container where there are a lot of PersistenceBroker objects that may be
> concurrently calling these methods (and running on a dual processor
> box).
>
> Thanks,
> - John Freeborg
>
>
> _______________________________________________
> Objectbridge-developers mailing list
> Obj...@li...
> https://lists.sourceforge.net/lists/listinfo/objectbridge-developers
>
>
>
>
|