WaitingThreadpublic class WaitingThread extends Object Represents a thread waiting for a connection.
This class implements throwaway objects. It is instantiated whenever
a thread needs to wait. Instances are not re-used, except if the
waiting thread experiences a spurious wakeup and continues to wait.
All methods assume external synchronization on the condition
passed to the constructor.
Instances of this class do not synchronize access! |
Fields Summary |
---|
private final Condition | condThe condition on which the thread is waiting. | private final RouteSpecificPool | poolThe route specific pool on which the thread is waiting. | private Thread | waiterThe thread that is waiting for an entry. | private boolean | abortedTrue if this was interrupted. |
Constructors Summary |
---|
public WaitingThread(Condition cond, RouteSpecificPool pool)Creates a new entry for a waiting thread.
if (cond == null) {
throw new IllegalArgumentException("Condition must not be null.");
}
this.cond = cond;
this.pool = pool;
|
Methods Summary |
---|
public boolean | await(java.util.Date deadline)Blocks the calling thread.
This method returns when the thread is notified or interrupted,
if a timeout occurrs, or if there is a spurious wakeup.
This method assumes external synchronization.
// This is only a sanity check. We cannot synchronize here,
// the lock would not be released on calling cond.await() below.
if (this.waiter != null) {
throw new IllegalStateException
("A thread is already waiting on this object." +
"\ncaller: " + Thread.currentThread() +
"\nwaiter: " + this.waiter);
}
if (aborted)
throw new InterruptedException("Operation interrupted");
this.waiter = Thread.currentThread();
boolean success = false;
try {
if (deadline != null) {
success = this.cond.awaitUntil(deadline);
} else {
this.cond.await();
success = true;
}
if (aborted)
throw new InterruptedException("Operation interrupted");
} finally {
this.waiter = null;
}
return success;
| public final java.util.concurrent.locks.Condition | getCondition()Obtains the condition.
// not synchronized
return this.cond;
| public final org.apache.http.impl.conn.tsccm.RouteSpecificPool | getPool()Obtains the pool, if there is one.
// not synchronized
return this.pool;
| public final java.lang.Thread | getThread()Obtains the thread, if there is one.
// not synchronized
return this.waiter;
| public void | interrupt()
aborted = true;
this.cond.signalAll();
| public void | wakeup()Wakes up the waiting thread.
This method assumes external synchronization.
// If external synchronization and pooling works properly,
// this cannot happen. Just a sanity check.
if (this.waiter == null) {
throw new IllegalStateException
("Nobody waiting on this object.");
}
// One condition might be shared by several WaitingThread instances.
// It probably isn't, but just in case: wake all, not just one.
this.cond.signalAll();
|
|