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