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;
    } 
 
Stop searching for code, let great code find you!  Add Codota to your java IDE