synchronize singleton constructor static getInstance method. dangerous otherwise
[mir.git] / source / mircoders / storage / DatabaseImageColor.java
index 05b895c..776bb18 100755 (executable)
@@ -22,7 +22,11 @@ public class DatabaseImageColor extends Database implements StorageObject{
        private static DatabaseImageColor instance;
        private static SimpleList publisherPopupData;
 
-       public static DatabaseImageColor 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 DatabaseImageColor getInstance() 
+         throws StorageObjectException
        {
                if (instance == null) {
                        instance = new DatabaseImageColor();
@@ -36,11 +40,10 @@ public class DatabaseImageColor extends Database implements StorageObject{
                super();
                this.hasTimestamp = false;
                this.theTable="img_color";
-               try { this.theEntityClass = Class.forName("mir.entity.EntityImageColor");       }
-               catch (Exception e) { throw new StorageObjectException(e.toString());   }
        }
 
-       public SimpleList getPopupData() { return getPopupData("name",true); }
+       public SimpleList getPopupData()
+        throws StorageObjectException { return getPopupData("name",true); }
 
 
 }