Class HostLimitQueue

  • All Implemented Interfaces:
    Serializable, Iterable<Runnable>, Collection<Runnable>, BlockingDeque<Runnable>, BlockingQueue<Runnable>, Deque<Runnable>, Queue<Runnable>

    public class HostLimitQueue
    extends LinkedBlockingDeque<Runnable>
    Queue for ThreadPoolExecutor that implements per-host limit. It will acquire a semaphore for each task and it will set a runnable task with semaphore release, when job has finished.

    This implementation doesn't guarantee to have at most hostLimit connections per host[1], and it doesn't guarantee that all threads will be busy, when there is work for them[2].
    [1] More connection per host may happen, when ThreadPoolExecutor is growing its pool, and thus tasks do not go through the Queue
    [2] If we have a queue, and for all hosts in queue we will fail to acquire semaphore, the thread take the first available job and wait for semaphore. It might be the case, that semaphore was released for some task further in queue, but this implementation doesn't try to detect such situation

    See Also:
    Serialized Form