org.norther.tammi.acorn.util.concurrent
Class TimeLimitedLock

java.lang.Object
  extended by org.norther.tammi.acorn.util.concurrent.TimeLimitedLock
All Implemented Interfaces:
Serializable, Lock

public class TimeLimitedLock
extends Object
implements Lock, Serializable

An adaptor class that lets any one thread to get a lock for a predetermined time only. After the time has elapsed, the lock will be released and the next waiting thread will get it. The lock and unlock must be made by the same thread.

Version:
$Id: TimeLimitedLock.java,v 1.7 2009/09/28 15:08:49 cvsimp Exp $
Author:
Ilkka Priha
See Also:
Serialized Form

Constructor Summary
TimeLimitedLock(Lock l, long t, TimeUnit unit)
          Constructs a new lock adapter.
 
Method Summary
 void lock()
           
 void lockInterruptibly()
           
 Condition newCondition()
           
 boolean tryLock()
           
 boolean tryLock(long t, TimeUnit unit)
           
 void unlock()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimeLimitedLock

public TimeLimitedLock(Lock l,
                       long t,
                       TimeUnit unit)
Constructs a new lock adapter.

Parameters:
l - the underlying lock.
t - the timeout for locks.
unit - the unit of the timeout.
Method Detail

lock

public void lock()
Specified by:
lock in interface Lock

lockInterruptibly

public void lockInterruptibly()
                       throws InterruptedException
Specified by:
lockInterruptibly in interface Lock
Throws:
InterruptedException

tryLock

public boolean tryLock()
Specified by:
tryLock in interface Lock

tryLock

public boolean tryLock(long t,
                       TimeUnit unit)
                throws InterruptedException
Specified by:
tryLock in interface Lock
Throws:
InterruptedException

unlock

public void unlock()
Specified by:
unlock in interface Lock

newCondition

public Condition newCondition()
Specified by:
newCondition in interface Lock


Copyright © 2004 The Norther Organization. All rights reserved.