From 168d9648b957e63f75fa8437314c7994fd5c2a74 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 13 Jun 2011 21:42:11 +0000 Subject: [PATCH] revised JMS CachedConnectionFactory to avoid unnecessary rollback calls on Session return (SPR-8437); fixed JMS CachedConnectionFactory to fully synchronize its Session list (SPR-8436) --- .../jms/connection/CachingConnectionFactory.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/org.springframework.jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java b/org.springframework.jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java index bf7a08e654..d2b2249e08 100644 --- a/org.springframework.jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java +++ b/org.springframework.jms/src/main/java/org/springframework/jms/connection/CachingConnectionFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2011 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. @@ -312,7 +312,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory { else if (methodName.equals("commit") || methodName.equals("rollback")) { this.transactionOpen = false; } - else { + else if (methodName.startsWith("create")) { this.transactionOpen = true; if (isCacheProducers() && (methodName.equals("createProducer") || methodName.equals("createSender") || methodName.equals("createPublisher"))) { @@ -408,11 +408,15 @@ public class CachingConnectionFactory extends SingleConnectionFactory { } } // Allow for multiple close calls... - if (!this.sessionList.contains(proxy)) { - if (logger.isTraceEnabled()) { - logger.trace("Returning cached Session: " + this.target); + boolean returned = false; + synchronized (this.sessionList) { + if (!this.sessionList.contains(proxy)) { + this.sessionList.addLast(proxy); + returned = true; } - this.sessionList.addLast(proxy); + } + if (returned && logger.isTraceEnabled()) { + logger.trace("Returned cached Session: " + this.target); } }