Author: manik.surtani(a)jboss.com
Date: 2007-11-12 10:37:53 -0500 (Mon, 12 Nov 2007)
New Revision: 4745
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
Log:
Additional timeout check
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2007-11-12
14:31:00 UTC (rev 4744)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2007-11-12
15:37:53 UTC (rev 4745)
@@ -304,6 +304,12 @@
n = cache.getRoot();
treeNodeSize = fqn.size();
+
+ // we need to make sure this loop doesn't take forever (under a lot of
concurrency) either as this can seem like a deadlock.
+ // apply a similar timeout check as is done in the loop that calls this lock()
method.
+ long expiryTime = System.currentTimeMillis() + timeout;
+ boolean reAcquisitionOnSameNode = false;
+
for (int i = -1; i < treeNodeSize; i++)
{
if (i == -1)
@@ -318,6 +324,9 @@
child_node = n.getChildDirect(child_name);
}
+ // timeout check
+ if (reAcquisitionOnSameNode && System.currentTimeMillis() >
expiryTime) throw new TimeoutException("Unable to acquire lock on child node " +
new Fqn(n.getFqn(), child_name) + " after " + timeout + " millis.");
+
if (log.isTraceEnabled()) log.trace("Directly got child node " +
child_name);
if (child_node == null && createIfNotExists)
{
@@ -373,8 +382,13 @@
// do the loop again, but don't assign child_node to n so that child_node
is processed again.
i--;
+ reAcquisitionOnSameNode = true;
continue;
}
+ else
+ {
+ reAcquisitionOnSameNode = false;
+ }
if (recursive && isTargetNode(i, treeNodeSize))
{
Show replies by thread