From 2895d73ed993c4f9d9e32116bf7c2ea0d3d089e8 Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Fri, 15 Feb 2008 17:49:47 +0000 Subject: protect the _currentException variable with its own lock, this avoids deadlocks between getCurrentException and the dispatcher thread git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@628132 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/qpid/client/AMQSession_0_10.java | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'java/client/src') diff --git a/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_10.java b/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_10.java index dd2b9a2389..407f1f3786 100644 --- a/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_10.java +++ b/java/client/src/main/java/org/apache/qpid/client/AMQSession_0_10.java @@ -70,6 +70,7 @@ public class AMQSession_0_10 extends AMQSession /** * The latest qpid Exception that has been reaised. */ + private Object _currentExceptionLock = new Object(); private QpidException _currentException; /** @@ -553,14 +554,17 @@ public class AMQSession_0_10 extends AMQSession * * @throws org.apache.qpid.AMQException get the latest thrown error. */ - public synchronized void getCurrentException() throws AMQException + public void getCurrentException() throws AMQException { - if (_currentException != null) + synchronized (_currentExceptionLock) { - QpidException toBeTrhown = _currentException; - _currentException = null; - throw new AMQException(AMQConstant.getConstant(toBeTrhown.getErrorCode().getCode()), - toBeTrhown.getMessage(), toBeTrhown); + if (_currentException != null) + { + QpidException toBeThrown = _currentException; + _currentException = null; + throw new AMQException(AMQConstant.getConstant(toBeThrown.getErrorCode().getCode()), + toBeThrown.getMessage(), toBeThrown); + } } } @@ -594,11 +598,11 @@ public class AMQSession_0_10 extends AMQSession { public void onClosed(ErrorCode errorCode, String reason, Throwable t) { - synchronized (this) + synchronized (_currentExceptionLock) { - //todo check the error code for finding out if we need to notify the + // todo check the error code for finding out if we need to notify the // JMS connection exception listener - _currentException = new QpidException(reason, errorCode, null); + _currentException = new QpidException(reason, errorCode, t); } } } -- cgit v1.2.1