Code example for Condition

Methods: await

0
            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 { 
            logger.info("Attempting to lock for result");