diff --git a/httpclient/src/main/java/org/apache/http/impl/conn/IdleConnectionHandler.java b/httpclient/src/main/java/org/apache/http/impl/conn/IdleConnectionHandler.java index d1b87ea14..c24a79369 100644 --- a/httpclient/src/main/java/org/apache/http/impl/conn/IdleConnectionHandler.java +++ b/httpclient/src/main/java/org/apache/http/impl/conn/IdleConnectionHandler.java @@ -35,11 +35,13 @@ import java.util.Iterator; import java.util.Map; import java.util.concurrent.TimeUnit; +import net.jcip.annotations.NotThreadSafe; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.http.HttpConnection; - +// Currently only used by AbstractConnPool /** * A helper class for connection managers to track idle connections. * @@ -49,6 +51,7 @@ import org.apache.http.HttpConnection; * * @since 4.0 */ +@NotThreadSafe public class IdleConnectionHandler { private final Log log = LogFactory.getLog(getClass()); diff --git a/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java b/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java index 659c70163..8cdae349b 100644 --- a/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java +++ b/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/AbstractConnPool.java @@ -60,7 +60,7 @@ import org.apache.http.impl.conn.IdleConnectionHandler; * * @since 4.0 */ -@NotThreadSafe // unsynch access to queues etc +@NotThreadSafe // unsynch access to refQueue, refWorker public abstract class AbstractConnPool implements RefQueueHandler { private final Log log = LogFactory.getLog(getClass()); @@ -77,10 +77,13 @@ public abstract class AbstractConnPool implements RefQueueHandler { * {@link BasicPoolEntryRef BasicPoolEntryRef}, * and point to the pool entry for the issued connection. * GCed connections are detected by the missing pool entries. + * Must hold poolLock when accessing. */ + @GuardedBy("poolLock") protected Set issuedConnections; - /** The handler for idle connections. */ + /** The handler for idle connections. Must hold poolLock when accessing. */ + @GuardedBy("poolLock") protected IdleConnectionHandler idleConnHandler; /** The current total number of connections. */ @@ -92,9 +95,11 @@ public abstract class AbstractConnPool implements RefQueueHandler { * The same queue is used to track loss of the connection manager, * so we cannot specialize the type. */ + // TODO - this needs to be synchronized, e.g. on Pool Lock protected ReferenceQueue refQueue; /** A worker (thread) to track loss of pool entries to GC. */ + // TODO - this needs to be synchronized, e.g. on Pool Lock private RefQueueWorker refWorker; @@ -127,7 +132,7 @@ public abstract class AbstractConnPool implements RefQueueHandler { public void enableConnectionGC() throws IllegalStateException { - if (refQueue != null) { + if (refQueue != null) { // TODO - this access is not guaranteed protected by the pool lock throw new IllegalStateException("Connection GC already enabled."); } poolLock.lock(); diff --git a/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java b/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java index b219eabe9..b56c27296 100644 --- a/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java +++ b/httpclient/src/main/java/org/apache/http/impl/conn/tsccm/RouteSpecificPool.java @@ -35,6 +35,8 @@ import java.util.ListIterator; import java.util.Queue; import java.util.LinkedList; +import net.jcip.annotations.NotThreadSafe; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.http.conn.OperatedClientConnection; @@ -49,12 +51,13 @@ import org.apache.http.util.LangUtils; * * @since 4.0 */ +@NotThreadSafe // e.g. numEntries, freeEntries, public class RouteSpecificPool { private final Log log = LogFactory.getLog(getClass()); /** The route this pool is for. */ - protected final HttpRoute route; + protected final HttpRoute route; //Immutable /** the maximum number of entries allowed for this pool */ protected final int maxEntries;