(no commit message)
[utils] / support / general / src / main / java / org / wamblee / cache / CachedObject.java
index 87feaf0e003f957d0f3310071fae9aab47c4cac4..da86298d6598115f9f5b4a683a27053c8f08da73 100644 (file)
@@ -79,10 +79,10 @@ public class CachedObject<KeyType extends Serializable, ValueType extends Serial
      * method may return different objects.
      * 
      * If the object is expired from the cache it is recomputed using the
-     * callback. In case the callback throws an exception the
-     * last known value is used. In case an exception is thrown, the problem is
-     * also logged. In case a recomputation is already being done by another
-     * thread, the last known value is immediately returned.
+     * callback. In case the callback throws an exception the last known value
+     * is used. In case an exception is thrown, the problem is also logged. In
+     * case a recomputation is already being done by another thread, the last
+     * known value is immediately returned.
      * 
      * @return Object.
      */
@@ -122,8 +122,9 @@ public class CachedObject<KeyType extends Serializable, ValueType extends Serial
                 computing = false;
             }
         }
-
-        return value;
+        synchronized (this) {
+            return value;
+        }
     }
 
     /**
@@ -151,9 +152,9 @@ public class CachedObject<KeyType extends Serializable, ValueType extends Serial
      */
     public static interface Computation<Key extends Serializable, Value extends Serializable> {
         /**
-         * Gets the object. Called when the object is not in the cache.
-         * In case computation fails, an exception should be thrown to ensure that the last 
-         * known value will be used. 
+         * Gets the object. Called when the object is not in the cache. In case
+         * computation fails, an exception should be thrown to ensure that the
+         * last known value will be used.
          * 
          * @param aObjectKey
          *            Id of the object in the cache.