Skip to content

Commit b6ecfcf

Browse files
committed
CachingConnectionFactory makes its Session caching inactive during reset
Issue: SPR-16450
1 parent 10caaef commit b6ecfcf

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

spring-jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ public boolean isCacheConsumers() {
175175
@Override
176176
public void resetConnection() {
177177
this.active = false;
178+
178179
synchronized (this.cachedSessions) {
179180
for (LinkedList<Session> sessionList : this.cachedSessions.values()) {
180181
synchronized (sessionList) {
@@ -190,17 +191,22 @@ public void resetConnection() {
190191
}
191192
this.cachedSessions.clear();
192193
}
193-
this.active = true;
194194

195195
// Now proceed with actual closing of the shared Connection...
196196
super.resetConnection();
197+
198+
this.active = true;
197199
}
198200

199201
/**
200202
* Checks for a cached Session for the given mode.
201203
*/
202204
@Override
203205
protected Session getSession(Connection con, Integer mode) throws JMSException {
206+
if (!this.active) {
207+
return null;
208+
}
209+
204210
LinkedList<Session> sessionList;
205211
synchronized (this.cachedSessions) {
206212
sessionList = this.cachedSessions.get(mode);
@@ -264,11 +270,9 @@ private class CachedSessionInvocationHandler implements InvocationHandler {
264270

265271
private final LinkedList<Session> sessionList;
266272

267-
private final Map<DestinationCacheKey, MessageProducer> cachedProducers =
268-
new HashMap<>();
273+
private final Map<DestinationCacheKey, MessageProducer> cachedProducers = new HashMap<>();
269274

270-
private final Map<ConsumerCacheKey, MessageConsumer> cachedConsumers =
271-
new HashMap<>();
275+
private final Map<ConsumerCacheKey, MessageConsumer> cachedConsumers = new HashMap<>();
272276

273277
private boolean transactionOpen = false;
274278

0 commit comments

Comments
 (0)