You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2014/04/16 13:50:55 UTC
svn commit: r1587880 - in
/httpcomponents/httpclient/branches/4.3.x/httpclient/src/main/java/org/apache/http/impl/conn:
BasicHttpClientConnectionManager.java PoolingHttpClientConnectionManager.java
Author: olegk
Date: Wed Apr 16 11:50:55 2014
New Revision: 1587880
URL: http://svn.apache.org/r1587880
Log:
HTTPCLIENT-1495: shut down standard connection managers only once
Modified:
httpcomponents/httpclient/branches/4.3.x/httpclient/src/main/java/org/apache/http/impl/conn/BasicHttpClientConnectionManager.java
httpcomponents/httpclient/branches/4.3.x/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java
Modified: httpcomponents/httpclient/branches/4.3.x/httpclient/src/main/java/org/apache/http/impl/conn/BasicHttpClientConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.3.x/httpclient/src/main/java/org/apache/http/impl/conn/BasicHttpClientConnectionManager.java?rev=1587880&r1=1587879&r2=1587880&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.3.x/httpclient/src/main/java/org/apache/http/impl/conn/BasicHttpClientConnectionManager.java (original)
+++ httpcomponents/httpclient/branches/4.3.x/httpclient/src/main/java/org/apache/http/impl/conn/BasicHttpClientConnectionManager.java Wed Apr 16 11:50:55 2014
@@ -32,6 +32,7 @@ import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.Date;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -107,8 +108,7 @@ public class BasicHttpClientConnectionMa
@GuardedBy("this")
private ConnectionConfig connConfig;
- @GuardedBy("this")
- private volatile boolean shutdown;
+ private final AtomicBoolean isShutdown;
private static Registry<ConnectionSocketFactory> getDefaultRegistry() {
return RegistryBuilder.<ConnectionSocketFactory>create()
@@ -129,6 +129,7 @@ public class BasicHttpClientConnectionMa
this.expiry = Long.MAX_VALUE;
this.socketConfig = SocketConfig.DEFAULT;
this.connConfig = ConnectionConfig.DEFAULT;
+ this.isShutdown = new AtomicBoolean(false);
}
public BasicHttpClientConnectionManager(
@@ -240,7 +241,7 @@ public class BasicHttpClientConnectionMa
}
synchronized HttpClientConnection getConnection(final HttpRoute route, final Object state) {
- Asserts.check(!this.shutdown, "Connection manager has been shut down");
+ Asserts.check(!this.isShutdown.get(), "Connection manager has been shut down");
if (this.log.isDebugEnabled()) {
this.log.debug("Get connection for route " + route);
}
@@ -267,8 +268,7 @@ public class BasicHttpClientConnectionMa
if (this.log.isDebugEnabled()) {
this.log.debug("Releasing connection " + conn);
}
- if (this.shutdown) {
- shutdownConnection();
+ if (this.isShutdown.get()) {
return;
}
try {
@@ -336,7 +336,7 @@ public class BasicHttpClientConnectionMa
}
public synchronized void closeExpiredConnections() {
- if (this.shutdown) {
+ if (this.isShutdown.get()) {
return;
}
if (!this.leased) {
@@ -346,7 +346,7 @@ public class BasicHttpClientConnectionMa
public synchronized void closeIdleConnections(final long idletime, final TimeUnit tunit) {
Args.notNull(tunit, "Time unit");
- if (this.shutdown) {
+ if (this.isShutdown.get()) {
return;
}
if (!this.leased) {
@@ -362,11 +362,9 @@ public class BasicHttpClientConnectionMa
}
public synchronized void shutdown() {
- if (this.shutdown) {
- return;
+ if (this.isShutdown.compareAndSet(false, true)) {
+ shutdownConnection();
}
- this.shutdown = true;
- shutdownConnection();
}
}
Modified: httpcomponents/httpclient/branches/4.3.x/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.3.x/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java?rev=1587880&r1=1587879&r2=1587880&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.3.x/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java (original)
+++ httpcomponents/httpclient/branches/4.3.x/httpclient/src/main/java/org/apache/http/impl/conn/PoolingHttpClientConnectionManager.java Wed Apr 16 11:50:55 2014
@@ -35,6 +35,7 @@ import java.util.concurrent.ExecutionExc
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -91,6 +92,7 @@ public class PoolingHttpClientConnection
private final ConfigData configData;
private final CPool pool;
private final HttpClientConnectionOperator connectionOperator;
+ private final AtomicBoolean isShutDown;
private static Registry<ConnectionSocketFactory> getDefaultRegistry() {
return RegistryBuilder.<ConnectionSocketFactory>create()
@@ -148,6 +150,7 @@ public class PoolingHttpClientConnection
new InternalConnectionFactory(this.configData, connFactory), 2, 20, timeToLive, tunit);
this.connectionOperator = new HttpClientConnectionOperator(
socketFactoryRegistry, schemePortResolver, dnsResolver);
+ this.isShutDown = new AtomicBoolean(false);
}
PoolingHttpClientConnectionManager(
@@ -160,6 +163,7 @@ public class PoolingHttpClientConnection
this.pool = pool;
this.connectionOperator = new HttpClientConnectionOperator(
socketFactoryRegistry, schemePortResolver, dnsResolver);
+ this.isShutDown = new AtomicBoolean(false);
}
@Override
@@ -342,13 +346,15 @@ public class PoolingHttpClientConnection
}
public void shutdown() {
- this.log.debug("Connection manager is shutting down");
- try {
- this.pool.shutdown();
- } catch (final IOException ex) {
- this.log.debug("I/O exception shutting down connection manager", ex);
+ if (this.isShutDown.compareAndSet(false, true)) {
+ this.log.debug("Connection manager is shutting down");
+ try {
+ this.pool.shutdown();
+ } catch (final IOException ex) {
+ this.log.debug("I/O exception shutting down connection manager", ex);
+ }
+ this.log.debug("Connection manager shut down");
}
- this.log.debug("Connection manager shut down");
}
public void closeIdleConnections(final long idleTimeout, final TimeUnit tunit) {