Code example for Lock

Methods: lockInterruptibly

0
        lock.lock();
    } 
 
    public void f() { 
        try { 
            lock.lockInterruptibly();
        } catch (InterruptedException e) {
            System.out.println("Interrupted from lock acquisition in f()");
        } 
    } 
} 
 
class Blocked2 implements Runnable {
    BlockedMutex blocked = new BlockedMutex();
 
    public void run() { 
        System.out.println("Waiting for f() in BlockMutex");
        blocked.f();
        System.out.println("Broken out of blocked call");
    } 
}