Code example for Lock

Methods: tryLock

0
        this.lock = lock;
        this.diff = diff;
    } 
 
    public void lock() throws InterruptedException, TimeoutException { 
        boolean timedOut = !lock.tryLock(10, SECONDS);
        if (timedOut) {
            throw new TimeoutException("could not get lock, timed out");
        } 
    } 
 
    public Diff lockThenGet() throws InterruptedException, TimeoutException { 
        boolean timedOut = !lock.tryLock(10, SECONDS);
        if (timedOut) {
            throw new TimeoutException("could not get lock, timed out");
        } 
 
        return diff;
    } 
 
    public void set(Diff newDiff) throws InterruptedException {