[OJB-developers] Double checked locking & OJB
Brought to you by:
thma
From: John F. <jfr...@so...> - 2002-04-11 18:38:44
|
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): public static LockManager getLockManager() { if (LOCKMAN =3D=3D null) { synchronized (LockManager.class) { // This would be DCL, but the code doesn't have this second check // if (LOCKMAN =3D=3D null) LOCKMAN =3D 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,=20 - John Freeborg |