diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java b/activemq-core/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java index 69584f5e03..aef5440852 100755 --- a/activemq-core/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/failover/FailoverTransport.java @@ -68,6 +68,7 @@ public class FailoverTransport implements CompositeTransport { private final CopyOnWriteArrayList uris = new CopyOnWriteArrayList(); private final Object reconnectMutex = new Object(); + private final Object backupMutex = new Object(); private final Object sleepMutex = new Object(); private final ConnectionStateTracker stateTracker = new ConnectionStateTracker(); private final ConcurrentHashMap requestMap = new ConcurrentHashMap(); @@ -633,26 +634,28 @@ public class FailoverTransport implements CompositeTransport { if (!useExponentialBackOff) { reconnectDelay = initialReconnectDelay; } - if (backup && !backups.isEmpty()) { - BackupTransport bt = backups.remove(0); - Transport t = bt.getTransport(); - URI uri = bt.getUri(); - t.setTransportListener(myTransportListener); - try { - if (started) { - restoreTransport(t); - } - reconnectDelay = initialReconnectDelay; - failedConnectTransportURI=null; - connectedTransportURI = uri; - connectedTransport.set(t); - reconnectMutex.notifyAll(); - connectFailures = 0; - LOG.info("Successfully reconnected to backup " + uri); - return false; - }catch (Exception e) { - LOG.debug("Backup transport failed",e); - } + synchronized(backupMutex) { + if (backup && !backups.isEmpty()) { + BackupTransport bt = backups.remove(0); + Transport t = bt.getTransport(); + URI uri = bt.getUri(); + t.setTransportListener(myTransportListener); + try { + if (started) { + restoreTransport(t); + } + reconnectDelay = initialReconnectDelay; + failedConnectTransportURI=null; + connectedTransportURI = uri; + connectedTransport.set(t); + reconnectMutex.notifyAll(); + connectFailures = 0; + LOG.info("Successfully reconnected to backup " + uri); + return false; + }catch (Exception e) { + LOG.debug("Backup transport failed",e); + } + } } Iterator iter = connectList.iterator(); @@ -742,7 +745,7 @@ public class FailoverTransport implements CompositeTransport { final boolean buildBackups() { - synchronized (reconnectMutex) { + synchronized (backupMutex) { if (!disposed && backup && backups.size() < backupPoolSize) { List connectList = getConnectList(); //removed disposed backups