Index: D:/My Documents/Eclipse Workspace/HttpClient/src/java/org/apache/commons/httpclient/SimpleHttpConnectionManager.java =================================================================== --- D:/My Documents/Eclipse Workspace/HttpClient/src/java/org/apache/commons/httpclient/SimpleHttpConnectionManager.java (revision 224435) +++ D:/My Documents/Eclipse Workspace/HttpClient/src/java/org/apache/commons/httpclient/SimpleHttpConnectionManager.java (working copy) @@ -33,6 +33,8 @@ import java.io.InputStream; import org.apache.commons.httpclient.params.HttpConnectionManagerParams; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** * A connection manager that provides access to a single HttpConnection. This @@ -49,6 +51,13 @@ */ public class SimpleHttpConnectionManager implements HttpConnectionManager { + private static final Log LOG = LogFactory.getLog(SimpleHttpConnectionManager.class); + + private static final String MISUSE_MESSAGE = + "SimpleHttpConnectionManager being used incorrectly. Be sure that" + + " HttpMethod.releaseConnection() is always called and that only one thread" + + " and/or method is using this connection manager at a time."; + /** * Since the same connection is about to be reused, make sure the * previous request was completely processed, and if not @@ -81,6 +90,14 @@ */ private long idleStartTime = Long.MAX_VALUE; + /** + * Used to test if {@link #httpConnection} is currently in use + * (i.e. checked out). This is only used as a sanity check to help + * debug cases where this connection manager is being used incorrectly. + * It will not be used to enforce thread safety. + */ + private volatile boolean inUse = false; + public SimpleHttpConnectionManager() { } @@ -157,6 +174,9 @@ // remove the connection from the timeout handler idleStartTime = Long.MAX_VALUE; + + if (inUse) LOG.warn(MISUSE_MESSAGE); + inUse = true; return httpConnection; } @@ -181,6 +201,9 @@ finishLastResponse(httpConnection); + if (!inUse) LOG.warn(MISUSE_MESSAGE); + inUse = false; + // track the time the connection was made idle idleStartTime = System.currentTimeMillis(); }