Code example for Lock

Methods: lockInterruptibly

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