Code example for Lock

Methods: tryLock, unlock

0
	} 
 
	public void timed() throws Exception { 
		boolean locked = false;
		try { 
			locked = lock.tryLock(2, TimeUnit.SECONDS);
			System.out.println("Locked " + locked);
		} catch (InterruptedException exc) {
			throw new Exception("Lock attempt interrupted.");
		} finally { 
			if (locked)
				lock.unlock();
		} 
 
	} 
 
	/** 
	 * @param args 
	 */ 
	public static void main(String[] args) {
		final AttemptLocking al = new AttemptLocking();