HTTPCLIENT-881: Methods mutating the internal state of the AbstractClientConnAdapter class and its subclasses made synchronized; ThreadSafeClientConnManager#releaseConnection method now synchronizes access to the BasicPooledConnAdapter instance

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@825999 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2009-10-16 16:52:30 +00:00
parent 90f9e38b8d
commit 077281ba27
4 changed files with 35 additions and 38 deletions

View File

@ -108,7 +108,7 @@ public abstract class AbstractClientConnAdapter implements ManagedClientConnecti
* Detaches this adapter from the wrapped connection.
* This adapter becomes useless.
*/
protected void detach() {
protected synchronized void detach() {
wrappedConnection = null;
connManager = null; // base class attribute
duration = Long.MAX_VALUE;
@ -310,7 +310,7 @@ public abstract class AbstractClientConnAdapter implements ManagedClientConnecti
}
}
public void releaseConnection() {
public synchronized void releaseConnection() {
if (shutdown) {
return;
}
@ -320,7 +320,7 @@ public abstract class AbstractClientConnAdapter implements ManagedClientConnecti
}
}
public void abortConnection() {
public synchronized void abortConnection() {
if (shutdown) {
return;
}

View File

@ -81,9 +81,9 @@ public abstract class AbstractPooledConnAdapter extends AbstractClientConnAdapte
* This adapter becomes useless.
*/
@Override
protected void detach() {
super.detach();
protected synchronized void detach() {
poolEntry = null;
super.detach();
}
public HttpRoute getRoute() {

View File

@ -26,13 +26,10 @@
package org.apache.http.impl.conn.tsccm;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.impl.conn.AbstractPoolEntry;
import org.apache.http.impl.conn.AbstractPooledConnAdapter;
/**
* A connection wrapper and callback handler.
* All connections given out by the manager are wrappers which
@ -72,7 +69,6 @@ public class BasicPooledConnAdapter extends AbstractPooledConnAdapter {
}
// non-javadoc, see base class
@Override
protected void detach() {
// override needed only to make method visible in this package

View File

@ -220,7 +220,11 @@ public class ThreadSafeClientConnManager implements ClientConnectionManager {
throw new IllegalArgumentException
("Connection not obtained from this manager.");
}
synchronized (hca) {
BasicPoolEntry entry = (BasicPoolEntry) hca.getPoolEntry();
if (entry == null) {
return;
}
try {
// make sure that the response has been read completely
if (hca.isOpen() && !hca.isMarkedReusable()) {
@ -235,12 +239,10 @@ public class ThreadSafeClientConnManager implements ClientConnectionManager {
hca.shutdown();
}
} catch (IOException iox) {
//@@@ log as warning? let pass?
if (log.isDebugEnabled())
log.debug("Exception shutting down released connection.",
iox);
} finally {
BasicPoolEntry entry = (BasicPoolEntry) hca.getPoolEntry();
boolean reusable = hca.isMarkedReusable();
if (log.isDebugEnabled()) {
if (reusable) {
@ -250,7 +252,6 @@ public class ThreadSafeClientConnManager implements ClientConnectionManager {
}
}
hca.detach();
if (entry != null) {
pool.freeEntry(entry, reusable, validDuration, timeUnit);
}
}