HTTPCLIENT-677: switching to new WaitingThread class
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@607289 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
caf0b10534
commit
a453692c09
|
@ -90,31 +90,6 @@ public class ConnPoolByRoute extends AbstractConnPool {
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* A thread and the pool in which it is waiting.
|
||||
* <!-- @@@ will be revised for HTTPCLIENT-677 -->
|
||||
*/
|
||||
protected static class WaitingThread {
|
||||
|
||||
/** The thread that is waiting for an entry. */
|
||||
public Thread thread;
|
||||
|
||||
/** The route specific pool the thread is waiting for. */
|
||||
public RouteSpecificPool pool;
|
||||
|
||||
/**
|
||||
* Indicates the source of an interruption.
|
||||
* Set to <code>true</code> inside
|
||||
* {@link #notifyWaitingThread(RouteSpecificPool)}
|
||||
* and {@link #shutdown shutdown()}
|
||||
* before the thread is interrupted.
|
||||
* If not set, the thread was interrupted from the outside.
|
||||
*/
|
||||
public boolean interruptedByConnectionPool = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new connection pool, managed by route.
|
||||
*
|
||||
|
@ -258,11 +233,12 @@ public class ConnPoolByRoute extends AbstractConnPool {
|
|||
}
|
||||
|
||||
if (waitingThread == null) {
|
||||
waitingThread = new WaitingThread();
|
||||
waitingThread.pool = rospl;
|
||||
waitingThread.thread = Thread.currentThread();
|
||||
waitingThread = new WaitingThread
|
||||
(poolLock.newCondition(), rospl);
|
||||
//@@@waitingThread.pool = rospl;
|
||||
//@@@waitingThread.thread = Thread.currentThread();
|
||||
} else {
|
||||
waitingThread.interruptedByConnectionPool = false;
|
||||
waitingThread.interruptedByConnectionPool = false;//@@@
|
||||
}
|
||||
|
||||
if (useTimeout) {
|
||||
|
@ -271,7 +247,8 @@ public class ConnPoolByRoute extends AbstractConnPool {
|
|||
|
||||
rospl.queueThread(waitingThread);
|
||||
waitingThreads.add(waitingThread);
|
||||
poolCondition.await(timeToWait, TimeUnit.MILLISECONDS);
|
||||
//@@@ poolCondition.await(timeToWait, TimeUnit.MILLISECONDS);
|
||||
waitingThread.await(timeToWait); //@@@, TimeUnit.MILLISECONDS);
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
if (!waitingThread.interruptedByConnectionPool) {
|
||||
|
@ -547,7 +524,7 @@ public class ConnPoolByRoute extends AbstractConnPool {
|
|||
LOG.debug("Notifying thread waiting on any pool.");
|
||||
}
|
||||
waitingThread = waitingThreads.remove();
|
||||
waitingThread.pool.removeThread(waitingThread);
|
||||
waitingThread.getPool().removeThread(waitingThread);
|
||||
|
||||
} else if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Notifying no-one, there are no waiting threads");
|
||||
|
@ -555,7 +532,7 @@ public class ConnPoolByRoute extends AbstractConnPool {
|
|||
|
||||
if (waitingThread != null) {
|
||||
waitingThread.interruptedByConnectionPool = true;
|
||||
waitingThread.thread.interrupt();
|
||||
waitingThread.getThread().interrupt(); //@@@ HTTPCLIENT-677
|
||||
}
|
||||
|
||||
} finally {
|
||||
|
@ -610,7 +587,7 @@ public class ConnPoolByRoute extends AbstractConnPool {
|
|||
WaitingThread waiter = iwth.next();
|
||||
iwth.remove();
|
||||
waiter.interruptedByConnectionPool = true;
|
||||
waiter.thread.interrupt();
|
||||
waiter.getThread().interrupt(); //@@@ HTTPCLIENT-677
|
||||
}
|
||||
|
||||
routeToPool.clear();
|
||||
|
|
|
@ -53,7 +53,7 @@ public class RouteSpecificPool {
|
|||
protected LinkedList<BasicPoolEntry> freeEntries;
|
||||
|
||||
/** The list of threads waiting for this pool. */
|
||||
protected Queue<ConnPoolByRoute.WaitingThread> waitingThreads;
|
||||
protected Queue<WaitingThread> waitingThreads;
|
||||
|
||||
/** The number of created entries. */
|
||||
protected int numEntries;
|
||||
|
@ -67,7 +67,7 @@ public class RouteSpecificPool {
|
|||
public RouteSpecificPool(HttpRoute r) {
|
||||
this.route = r;
|
||||
this.freeEntries = new LinkedList<BasicPoolEntry>();
|
||||
this.waitingThreads = new LinkedList<ConnPoolByRoute.WaitingThread>();
|
||||
this.waitingThreads = new LinkedList<WaitingThread>();
|
||||
this.numEntries = 0;
|
||||
}
|
||||
|
||||
|
@ -207,7 +207,7 @@ public class RouteSpecificPool {
|
|||
*
|
||||
* @param wt the waiting thread
|
||||
*/
|
||||
public void queueThread(ConnPoolByRoute.WaitingThread wt) {
|
||||
public void queueThread(WaitingThread wt) {
|
||||
if (wt == null) {
|
||||
throw new IllegalArgumentException
|
||||
("Waiting thread must not be null.");
|
||||
|
@ -232,7 +232,7 @@ public class RouteSpecificPool {
|
|||
*
|
||||
* @return a waiting thread, or <code>null</code> if there is none
|
||||
*/
|
||||
public ConnPoolByRoute.WaitingThread dequeueThread() {
|
||||
public WaitingThread dequeueThread() {
|
||||
return this.waitingThreads.poll();
|
||||
}
|
||||
|
||||
|
@ -242,7 +242,7 @@ public class RouteSpecificPool {
|
|||
*
|
||||
* @param wt the waiting thread
|
||||
*/
|
||||
public void removeThread(ConnPoolByRoute.WaitingThread wt) {
|
||||
public void removeThread(WaitingThread wt) {
|
||||
if (wt == null)
|
||||
return;
|
||||
|
||||
|
|
|
@ -68,7 +68,8 @@ public class WaitingThread {
|
|||
* before the thread is interrupted.
|
||||
* If not set, the thread was interrupted from the outside.
|
||||
*/
|
||||
private boolean interruptedByConnectionPool;
|
||||
//@@@ to be removed in HTTPCLIENT-677
|
||||
/*default@@@*/ boolean interruptedByConnectionPool;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -100,10 +101,11 @@ public class WaitingThread {
|
|||
*
|
||||
* @see #wakeup
|
||||
*/
|
||||
public void await(int timeout)
|
||||
public void await(long timeout)
|
||||
throws InterruptedException {
|
||||
|
||||
//@@@ check timeout for negative, or assume overflow?
|
||||
//@@@ for now, leave the check to the condition
|
||||
|
||||
// This is only a sanity check. We cannot not synchronize here,
|
||||
// the lock would not be released on calling cond.await() below.
|
||||
|
@ -117,8 +119,6 @@ public class WaitingThread {
|
|||
this.waiter = Thread.currentThread();
|
||||
|
||||
try {
|
||||
//@@@ how to convert the int timeout to the long argument?
|
||||
//@@@ (timeout & 0xffffffffL)? or check for negative above?
|
||||
this.cond.await(timeout, TimeUnit.MILLISECONDS);
|
||||
} finally {
|
||||
this.waiter = null;
|
||||
|
|
Loading…
Reference in New Issue