com.trendrr.oss.concurrent
Class PeriodicLock

java.lang.Object
  extended by com.trendrr.oss.concurrent.PeriodicLock

public class PeriodicLock
extends java.lang.Object

this lock will allow one thread access every x milliseconds. all threads will block while the single thread has the lock. it is useful for reinitialization code.

Author:
dustin

Constructor Summary
PeriodicLock(long delay, long period)
           
 
Method Summary
 java.util.Date getNextUnlock()
           
 boolean lockOrSkip()
          same as above, only will return false if the timedlock is locked or if another thread is accessing the restricted code.
 boolean lockOrWait()
          will return true if the lock is obtained.
 void lockUntil(java.util.Date date)
          forces the next time the lock will unlock.
 void unlock()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PeriodicLock

public PeriodicLock(long delay,
                    long period)
Method Detail

lockOrWait

public boolean lockOrWait()
will return true if the lock is obtained. false otherwise. will block if another thread currently holds the lock, then will return false when the other thread releases the lock.

Returns:

lockOrSkip

public boolean lockOrSkip()
same as above, only will return false if the timedlock is locked or if another thread is accessing the restricted code.

Returns:

unlock

public void unlock()

lockUntil

public void lockUntil(java.util.Date date)
forces the next time the lock will unlock.

Parameters:
date -

getNextUnlock

public java.util.Date getNextUnlock()