Example usage for org.apache.http.impl.conn.tsccm RouteSpecificPool nextThread

List of usage examples for org.apache.http.impl.conn.tsccm RouteSpecificPool nextThread

Introduction

In this page you can find the example usage for org.apache.http.impl.conn.tsccm RouteSpecificPool nextThread.

Prototype

public WaitingThread nextThread() 

Source Link

Document

Returns the next thread in the queue.

Usage

From source file:org.apache.http.impl.conn.tsccm.ConnPoolByRoute.java

/**
 * Notifies a waiting thread that a connection is available.
 * This will wake a thread waiting in the specific route pool,
 * if there is one.//w  w  w .j  a v  a2s.  c  om
 * Otherwise, a thread in the connection pool will be notified.
 *
 * @param rospl     the pool in which to notify, or <code>null</code>
 */
protected void notifyWaitingThread(final RouteSpecificPool rospl) {

    //@@@ while this strategy provides for best connection re-use,
    //@@@ is it fair? only do this if the connection is open?
    // Find the thread we are going to notify. We want to ensure that
    // each waiting thread is only interrupted once, so we will remove
    // it from all wait queues before interrupting.
    WaitingThread waitingThread = null;

    poolLock.lock();
    try {

        if ((rospl != null) && rospl.hasThread()) {
            if (log.isDebugEnabled()) {
                log.debug("Notifying thread waiting on pool" + " [" + rospl.getRoute() + "]");
            }
            waitingThread = rospl.nextThread();
        } else if (!waitingThreads.isEmpty()) {
            if (log.isDebugEnabled()) {
                log.debug("Notifying thread waiting on any pool");
            }
            waitingThread = waitingThreads.remove();
        } else if (log.isDebugEnabled()) {
            log.debug("Notifying no-one, there are no waiting threads");
        }

        if (waitingThread != null) {
            waitingThread.wakeup();
        }

    } finally {
        poolLock.unlock();
    }
}