synchronize singleton constructor static getInstance method. dangerous otherwise
[mir.git] / source / mircoders / storage / DatabaseUsers.java
index dd03a1b..69ab256 100755 (executable)
@@ -21,7 +21,11 @@ public class DatabaseUsers extends Database implements StorageObject{
 
        private static DatabaseUsers instance;
 
-       public static DatabaseUsers getInstance() throws StorageObjectException {
+       // the following *has* to be sychronized cause this static method
+       // could get preemted and we could end up with 2 instances of DatabaseFoo..
+       // see the "Singletons with needles and thread" article at JavaWorld -mh
+       public synchronized static DatabaseUsers getInstance() 
+         throws StorageObjectException {
                if (instance == null) {
                        instance = new DatabaseUsers();
                        instance.myselfDatabase = instance;
@@ -42,7 +46,7 @@ public class DatabaseUsers extends Database implements StorageObject{
                }
        }
 
-       public SimpleList getPopupData() {
+       public SimpleList getPopupData() throws StorageObjectException {
                return getPopupData("login",true);
        }
 }