Author: julien_viet
Date: 2011-10-03 12:20:33 -0400 (Mon, 03 Oct 2011)
New Revision: 7615
Added:
portal/trunk/component/common/src/main/java/org/exoplatform/commons/cache/future/Retrieval.java
Log:
GTNPORTAL-2148 : Detect reentrancy in future cache to prevent self deadlock
Added:
portal/trunk/component/common/src/main/java/org/exoplatform/commons/cache/future/Retrieval.java
===================================================================
---
portal/trunk/component/common/src/main/java/org/exoplatform/commons/cache/future/Retrieval.java
(rev 0)
+++
portal/trunk/component/common/src/main/java/org/exoplatform/commons/cache/future/Retrieval.java 2011-10-03
16:20:33 UTC (rev 7615)
@@ -0,0 +1,53 @@
+package org.exoplatform.commons.cache.future;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.FutureTask;
+
+/** @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a> */
+class Retrieval<K, V, C> implements Callable<V>
+{
+
+ /** . */
+ private final C context;
+
+ /** . */
+ private final K key;
+
+ /** . */
+ private final FutureCache<K, V, C> cache;
+
+ /** . */
+ final FutureTask<V> future;
+
+ /** Avoid reentrancy. */
+ transient Thread current;
+
+ public Retrieval(C context, K key, FutureCache<K, V, C> cache)
+ {
+ this.key = key;
+ this.context = context;
+ this.future = new FutureTask<V>(this);
+ this.cache = cache;
+ this.current = null;
+ }
+
+ public V call() throws Exception
+ {
+ // Retrieve the value from the loader
+ V value = cache.loader.retrieve(context, key);
+
+ //
+ if (value != null)
+ {
+ // Cache it, it is made available to other threads (unless someone removes it)
+ cache.put(key, value);
+
+ // Return value
+ return value;
+ }
+ else
+ {
+ return null;
+ }
+ }
+}
Show replies by date