Code example for ReentrantLock

Methods: tryLock, unlock

0
	} 
	 
	public void timed(){ 
		boolean captured=false;
		try{ 
			captured=lock.tryLock(2, TimeUnit.SECONDS);
		}catch(InterruptedException e){
			throw new RuntimeException(e);
		} 
		try{ 
			System.out.println("tryLock(2,TimeUnit.SECONDS):"+captured);
		}finally{ 
			if(captured)
				lock.unlock();
		} 
	} 
	 
	public static void main(String[] args){
		final AttemptLocking al=new AttemptLocking();
		al.untimted();
		al.timed();