You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ff...@apache.org on 2009/04/08 07:33:04 UTC
svn commit: r763113 -
/servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/nmr/flow/AbstractFlow.java
Author: ffang
Date: Wed Apr 8 05:33:04 2009
New Revision: 763113
URL: http://svn.apache.org/viewvc?rev=763113&view=rev
Log:
[SM-1840]use ReentrantReadWriteLock.WriteLock.tryLock with configurable timeout to avoild potential deadlock
Modified:
servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/nmr/flow/AbstractFlow.java
Modified: servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/nmr/flow/AbstractFlow.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/nmr/flow/AbstractFlow.java?rev=763113&r1=763112&r2=763113&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/nmr/flow/AbstractFlow.java (original)
+++ servicemix/smx3/branches/servicemix-3.2/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/nmr/flow/AbstractFlow.java Wed Apr 8 05:33:04 2009
@@ -16,6 +16,7 @@
*/
package org.apache.servicemix.jbi.nmr.flow;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReadWriteLock;
import javax.jbi.JBIException;
@@ -55,7 +56,9 @@
private ReadWriteLock lock = new ReentrantReadWriteLock();
private Thread suspendThread;
private String name;
-
+ private int writeLockTimeout = 5;
+
+
/**
* Initialize the Region
*
@@ -133,7 +136,11 @@
if (log.isDebugEnabled()) {
log.debug("Called Flow suspend");
}
- lock.writeLock().lock();
+ try {
+ lock.writeLock().tryLock(writeLockTimeout, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ log.debug("try lock interrupted");
+ }
suspendThread = Thread.currentThread();
}
@@ -144,7 +151,11 @@
if (log.isDebugEnabled()) {
log.debug("Called Flow resume");
}
- lock.writeLock().unlock();
+ try {
+ lock.writeLock().unlock();
+ } catch (IllegalMonitorStateException e) {
+ log.debug("not hold the write lock");
+ }
suspendThread = null;
}
@@ -272,4 +283,21 @@
return executorFactory;
}
+ /**
+ * Specifies the interval for which ReentrantReadWriteLock.WriteLock.tryLock will elapse,
+ * This is specified in seconds.
+ *
+ * @param writeLockTimeout
+ * the number of second ReentrantReadWriteLock.WriteLock.tryLock will elapse
+ * @org.apache.xbean.Property description="the number of second ReentrantReadWriteLock.WriteLock.tryLock will elapse.
+ * The default is 5 secs."
+ */
+ public void setWriteLockTimeout(int writeLockTimeout) {
+ this.writeLockTimeout = writeLockTimeout;
+ }
+
+ public int getWriteLockTimeout() {
+ return writeLockTimeout;
+ }
+
}