Code example for Lock

Methods: locknewConditionunlock

        this.adder = adder;
    public int add(int a, int b) {
        try { 
            condition = lock.newCondition();
  "Calling Vendor Addition");
            adder.add(a, b, this);
  "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 { 
    public void withResult(int result) {
        try { 
Contextual code suggestions in your IDE  Get Codota for Java