Skip to content

Commit 168d964

Browse files
committed
revised JMS CachedConnectionFactory to avoid unnecessary rollback calls on Session return (SPR-8437); fixed JMS CachedConnectionFactory to fully synchronize its Session list (SPR-8436)
1 parent 883ac31 commit 168d964

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2010 the original author or authors.
2+
* Copyright 2002-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -312,7 +312,7 @@ else if (methodName.equals("getTargetSession")) {
312312
else if (methodName.equals("commit") || methodName.equals("rollback")) {
313313
this.transactionOpen = false;
314314
}
315-
else {
315+
else if (methodName.startsWith("create")) {
316316
this.transactionOpen = true;
317317
if (isCacheProducers() && (methodName.equals("createProducer") ||
318318
methodName.equals("createSender") || methodName.equals("createPublisher"))) {
@@ -408,11 +408,15 @@ private void logicalClose(Session proxy) throws JMSException {
408408
}
409409
}
410410
// Allow for multiple close calls...
411-
if (!this.sessionList.contains(proxy)) {
412-
if (logger.isTraceEnabled()) {
413-
logger.trace("Returning cached Session: " + this.target);
411+
boolean returned = false;
412+
synchronized (this.sessionList) {
413+
if (!this.sessionList.contains(proxy)) {
414+
this.sessionList.addLast(proxy);
415+
returned = true;
414416
}
415-
this.sessionList.addLast(proxy);
417+
}
418+
if (returned && logger.isTraceEnabled()) {
419+
logger.trace("Returned cached Session: " + this.target);
416420
}
417421
}
418422

0 commit comments

Comments
 (0)