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

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

Introduction

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

Prototype

public boolean hasThread() 

Source Link

Document

Checks whether there is a waiting thread in this pool.

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  ww.  ja  v a  2 s. co  m
 * 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();
    }
}