Code example for Lock

Methods: newCondition

class FetchRequestQueue { 
    private final LinkedList<FetchRequest> queue = new LinkedList<FetchRequest>();
    private final Lock lock = new ReentrantLock();
    private final Condition available = this.lock.newCondition();
     * Thread designated to wait for the element at the head of the queue. This 
     * variant of the Leader-Follower pattern 
     * ( serves to minimize 
     * unnecessary timed waiting. When a thread becomes the leader, it waits 
     * only for the next delay to elapse, but other threads await indefinitely. 
     * The leader thread must signal some other thread before returning from 
     * take() or poll(...), unless some other thread becomes leader in the 
     * interim. Whenever the head of the queue is replaced with an element with 
     * an earlier expiration time, the leader field is invalidated by being 
     * reset to null, and some waiting thread, but not necessarily the current 
     * leader, is signalled. So waiting threads must be prepared to acquire and 
     * lose leadership while waiting. 
Connect your IDE to all the code out there  Get Codota for Java