Concurrency documentation

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@756799 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastian Bazley 2009-03-20 23:05:07 +00:00
parent 7c1fa0fda3
commit 6b57ed5755
3 changed files with 16 additions and 5 deletions

View File

@ -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());

View File

@ -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<BasicPoolEntryRef> 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<Object> 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();

View File

@ -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;