mirror of https://github.com/apache/activemq.git
ported fixed in 4.1 to trunk. http://issues.apache.org/activemq/browse/AMQ-1178
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@514668 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
477fc859e6
commit
ef1d3559f5
|
@ -51,6 +51,7 @@ public class ConnectionPool {
|
||||||
private ObjectPoolFactory poolFactory;
|
private ObjectPoolFactory poolFactory;
|
||||||
private long lastUsed = System.currentTimeMillis();
|
private long lastUsed = System.currentTimeMillis();
|
||||||
private boolean hasFailed;
|
private boolean hasFailed;
|
||||||
|
private boolean hasExpired;
|
||||||
private int idleTimeout = 30*1000;
|
private int idleTimeout = 30*1000;
|
||||||
|
|
||||||
public ConnectionPool(ActiveMQConnection connection, ObjectPoolFactory poolFactory, TransactionManager transactionManager) {
|
public ConnectionPool(ActiveMQConnection connection, ObjectPoolFactory poolFactory, TransactionManager transactionManager) {
|
||||||
|
@ -123,6 +124,7 @@ public class ConnectionPool {
|
||||||
|
|
||||||
synchronized public void close() {
|
synchronized public void close() {
|
||||||
if( connection!=null ) {
|
if( connection!=null ) {
|
||||||
|
try {
|
||||||
Iterator i = cache.values().iterator();
|
Iterator i = cache.values().iterator();
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
SessionPool pool = (SessionPool) i.next();
|
SessionPool pool = (SessionPool) i.next();
|
||||||
|
@ -132,16 +134,20 @@ public class ConnectionPool {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
try {
|
try {
|
||||||
connection.close();
|
connection.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
} finally {
|
||||||
connection = null;
|
connection = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
synchronized public void incrementReferenceCount() {
|
synchronized public void incrementReferenceCount() {
|
||||||
referenceCount++;
|
referenceCount++;
|
||||||
|
lastUsed = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized public void decrementReferenceCount() {
|
synchronized public void decrementReferenceCount() {
|
||||||
|
@ -156,10 +162,17 @@ public class ConnectionPool {
|
||||||
* @return true if this connection has expired.
|
* @return true if this connection has expired.
|
||||||
*/
|
*/
|
||||||
synchronized public boolean expiredCheck() {
|
synchronized public boolean expiredCheck() {
|
||||||
if( connection == null )
|
if( connection == null ) {
|
||||||
return true;
|
return true;
|
||||||
long t = System.currentTimeMillis();
|
}
|
||||||
if( hasFailed || idleTimeout> 0 && t > lastUsed+idleTimeout ) {
|
if( hasExpired ) {
|
||||||
|
if( referenceCount == 0 ) {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if( hasFailed || ( idleTimeout>0 && System.currentTimeMillis() > lastUsed+idleTimeout) ) {
|
||||||
|
hasExpired=true;
|
||||||
if( referenceCount == 0 ) {
|
if( referenceCount == 0 ) {
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue