Release shared JMS Connection before stop completion callback
Closes gh-30612
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -205,10 +205,7 @@ public abstract class AbstractJmsListeningContainer extends JmsDestinationAccess
|
||||
doInitialize();
|
||||
}
|
||||
catch (JMSException ex) {
|
||||
synchronized (this.sharedConnectionMonitor) {
|
||||
ConnectionFactoryUtils.releaseConnection(this.sharedConnection, getConnectionFactory(), this.autoStartup);
|
||||
this.sharedConnection = null;
|
||||
}
|
||||
releaseSharedConnection();
|
||||
throw convertJmsAccessException(ex);
|
||||
}
|
||||
}
|
||||
@@ -248,10 +245,7 @@ public abstract class AbstractJmsListeningContainer extends JmsDestinationAccess
|
||||
}
|
||||
finally {
|
||||
if (sharedConnectionEnabled()) {
|
||||
synchronized (this.sharedConnectionMonitor) {
|
||||
ConnectionFactoryUtils.releaseConnection(this.sharedConnection, getConnectionFactory(), false);
|
||||
this.sharedConnection = null;
|
||||
}
|
||||
releaseSharedConnection();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -391,9 +385,7 @@ public abstract class AbstractJmsListeningContainer extends JmsDestinationAccess
|
||||
*/
|
||||
protected final void refreshSharedConnection() throws JMSException {
|
||||
synchronized (this.sharedConnectionMonitor) {
|
||||
ConnectionFactoryUtils.releaseConnection(
|
||||
this.sharedConnection, getConnectionFactory(), this.sharedConnectionStarted);
|
||||
this.sharedConnection = null;
|
||||
releaseSharedConnection();
|
||||
this.sharedConnection = createSharedConnection();
|
||||
if (this.sharedConnectionStarted) {
|
||||
this.sharedConnection.start();
|
||||
@@ -474,6 +466,19 @@ public abstract class AbstractJmsListeningContainer extends JmsDestinationAccess
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Release the shared Connection, if any.
|
||||
* @since 6.1
|
||||
* @see ConnectionFactoryUtils#releaseConnection
|
||||
*/
|
||||
protected final void releaseSharedConnection() {
|
||||
synchronized (this.sharedConnectionMonitor) {
|
||||
ConnectionFactoryUtils.releaseConnection(
|
||||
this.sharedConnection, getConnectionFactory(), this.sharedConnectionStarted);
|
||||
this.sharedConnection = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the shared JMS Connection maintained by this container.
|
||||
* Available after initialization.
|
||||
|
||||
@@ -1245,9 +1245,15 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe
|
||||
|
||||
private void decreaseActiveInvokerCount() {
|
||||
activeInvokerCount--;
|
||||
if (stopCallback != null && activeInvokerCount == 0) {
|
||||
stopCallback.run();
|
||||
stopCallback = null;
|
||||
if (activeInvokerCount == 0) {
|
||||
if (!isRunning()) {
|
||||
// Proactively release shared Connection when stopped.
|
||||
releaseSharedConnection();
|
||||
}
|
||||
if (stopCallback != null) {
|
||||
stopCallback.run();
|
||||
stopCallback = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user