synchronize singleton constructor static getInstance method. dangerous otherwise
[mir.git] / source / mircoders / storage / DatabaseImageLayout.java
index d67596c..204c0ba 100755 (executable)
@@ -22,7 +22,11 @@ public class DatabaseImageLayout extends Database implements StorageObject{
        private static DatabaseImageLayout instance;
        private static SimpleList publisherPopupData;
 
-       public static DatabaseImageLayout 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 DatabaseImageLayout getInstance() 
+         throws StorageObjectException
        {
                if (instance == null) {
                        instance = new DatabaseImageLayout();