Code example for Lock

Methods: lock, newCondition, unlock

0
        this.adder = adder;
    } 
 
    public int add(int a, int b) {
        try { 
            lock.lock();
            condition = lock.newCondition();
            logger.info("Calling Vendor Addition");
            adder.add(a, b, this);
            logger.info("Awaiting signal from caller");
            condition.await(5, TimeUnit.SECONDS);
            if(result == null) {
                throw new RuntimeException("Vendor addition timed out");
            } 
            /** If the Vendor called this in the same thread*/ 
            return result;
        } catch (InterruptedException e) {
            throw new RuntimeException("Unable to compute the sum", e);
        } finally { 
            lock.unlock();
        } 
    } 
 
    public void withResult(int result) {
        try {