You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by jl...@apache.org on 2007/03/05 14:55:57 UTC

svn commit: r514668 - /activemq/trunk/activemq-core/src/main/java/org/apache/activemq/pool/ConnectionPool.java

Author: jlim
Date: Mon Mar  5 05:55:57 2007
New Revision: 514668

URL: http://svn.apache.org/viewvc?view=rev&rev=514668
Log:
ported fixed in 4.1 to trunk.  http://issues.apache.org/activemq/browse/AMQ-1178

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/pool/ConnectionPool.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/pool/ConnectionPool.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/pool/ConnectionPool.java?view=diff&rev=514668&r1=514667&r2=514668
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/pool/ConnectionPool.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/pool/ConnectionPool.java Mon Mar  5 05:55:57 2007
@@ -51,6 +51,7 @@
     private ObjectPoolFactory poolFactory;
 	private long lastUsed = System.currentTimeMillis();
 	private boolean hasFailed;
+	private boolean hasExpired;
 	private int idleTimeout = 30*1000;
 
     public ConnectionPool(ActiveMQConnection connection, ObjectPoolFactory poolFactory, TransactionManager transactionManager) {
@@ -123,25 +124,30 @@
 
     synchronized public void close() {
     	if( connection!=null ) {
-	        Iterator i = cache.values().iterator();
-	        while (i.hasNext()) {
-	            SessionPool pool = (SessionPool) i.next();
-	            i.remove();
-	            try {
-	                pool.close();
-	            } catch (Exception e) {
-	            }
-	        }
-            try {
-            	connection.close();
-            } catch (Exception e) {
-            }
-	        connection = null;
+    		try {
+		        Iterator i = cache.values().iterator();
+		        while (i.hasNext()) {
+		            SessionPool pool = (SessionPool) i.next();
+		            i.remove();
+		            try {
+		                pool.close();
+		            } catch (Exception e) {
+		            }
+		        }
+    		} finally {
+                try {
+                	connection.close();
+                } catch (Exception e) {
+                } finally {
+        	        connection = null;
+                }
+    		}
     	}
     }
 
     synchronized public void incrementReferenceCount() {
 		referenceCount++;
+		lastUsed = System.currentTimeMillis();
 	}
 
 	synchronized public void decrementReferenceCount() {
@@ -156,10 +162,17 @@
 	 * @return true if this connection has expired.
 	 */
 	synchronized public boolean expiredCheck() {
-		if( connection == null )
+		if( connection == null ) {
+			return true;
+		}
+		if( hasExpired ) {
+			if( referenceCount == 0 ) {
+				close();
+			}
 			return true;
-        long t = System.currentTimeMillis();
-		if( hasFailed || idleTimeout> 0 && t > lastUsed+idleTimeout ) {
+		}
+		if( hasFailed || ( idleTimeout>0 && System.currentTimeMillis() > lastUsed+idleTimeout) ) {
+			hasExpired=true;
 			if( referenceCount == 0 ) {
 				close();
 			}