activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r511079 - in /activemq/branches/activemq-4.1: ./ activemq-core/src/main/java/org/apache/activemq/pool/ConnectionPool.java
Date Fri, 23 Feb 2007 20:22:36 GMT
Author: chirino
Date: Fri Feb 23 12:22:35 2007
New Revision: 511079

URL: http://svn.apache.org/viewvc?view=rev&rev=511079
Log:
 r235@34:  chirino | 2007-02-23 14:47:58 -0500
 Fix pooling expiration so that it does not keep creating connections.
 
 

Modified:
    activemq/branches/activemq-4.1/   (props changed)
    activemq/branches/activemq-4.1/activemq-core/src/main/java/org/apache/activemq/pool/ConnectionPool.java

Propchange: activemq/branches/activemq-4.1/
------------------------------------------------------------------------------
--- svk:merge (original)
+++ svk:merge Fri Feb 23 12:22:35 2007
@@ -1 +1 @@
-635f1f41-eb29-0410-ac9d-be9e2c357fdd:/local/amq-4.1-port:234
+635f1f41-eb29-0410-ac9d-be9e2c357fdd:/local/amq-4.1-port:235

Modified: activemq/branches/activemq-4.1/activemq-core/src/main/java/org/apache/activemq/pool/ConnectionPool.java
URL: http://svn.apache.org/viewvc/activemq/branches/activemq-4.1/activemq-core/src/main/java/org/apache/activemq/pool/ConnectionPool.java?view=diff&rev=511079&r1=511078&r2=511079
==============================================================================
--- activemq/branches/activemq-4.1/activemq-core/src/main/java/org/apache/activemq/pool/ConnectionPool.java
(original)
+++ activemq/branches/activemq-4.1/activemq-core/src/main/java/org/apache/activemq/pool/ConnectionPool.java
Fri Feb 23 12:22:35 2007
@@ -45,6 +45,7 @@
     private ObjectPoolFactory poolFactory;
 	private long lastUsed;
 	private boolean hasFailed;
+	private boolean hasExpired;
 	private int idleTimeout = 30*1000;
 
     public ConnectionPool(ActiveMQConnection connection, ObjectPoolFactory poolFactory) {
@@ -94,25 +95,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() {
@@ -127,9 +133,17 @@
 	 * @return true if this connection has expired.
 	 */
 	synchronized public boolean expiredCheck() {
-		if( connection == null )
+		if( connection == null ) {
 			return true;
-		if( hasFailed || idleTimeout> 0 && System.currentTimeMillis() > lastUsed+idleTimeout
) {
+		}
+		if( hasExpired ) {
+			if( referenceCount == 0 ) {
+				close();
+			}
+			return true;
+		}
+		if( hasFailed || ( idleTimeout>0 && System.currentTimeMillis() > lastUsed+idleTimeout)
) {
+			hasExpired=true;
 			if( referenceCount == 0 ) {
 				close();
 			}



Mime
View raw message