Code example for Lock

Methods: lock, unlock

0
    } 
 
 
    public void offer(FetchRequest e) {
        final Lock lock = this.lock;
        lock.lock();
        try { 
            /** 
             * A request is not referenced by this queue,so we don't want to add 
             * it. 
             */ 
            if (e.getRefQueue() != null && e.getRefQueue() != this) {
                return; 
            } 
            // Reference to request. 
            e.setRefQueue(this);
            this.queue.offer(e);
            Collections.sort(this.queue);
            // Leader is changed. 
            if (this.queue.peek() == e) {
                this.leader = null;
                this.available.signal();
            } 
        } 
        finally { 
            lock.unlock();
        } 
    } 
 
 
    public int size() {