org.entityfs.lock.impl
Class TimeoutLockAcquiringStrategy

java.lang.Object
  extended by org.entityfs.lock.impl.AbstractLockAcquiringStrategy
      extended by org.entityfs.lock.impl.TimeoutLockAcquiringStrategy
All Implemented Interfaces:
LockAcquiringStrategy

public final class TimeoutLockAcquiringStrategy
extends AbstractLockAcquiringStrategy
implements LockAcquiringStrategy

This is a LockAcquiringStrategy that uses a timeout limit for how long it can wait to get a lock. If it cannot acquire a lock within the allocated time, it will throw an UncheckedInterruptedException.

If a lock cannot be acquired, that may indicate a thread deadlock.

Since:
1.0
Author:
Karl Gustafsson
In_jar:
entityfs-core

Field Summary
static TimeoutLockAcquiringStrategy INSTANCE
           
 
Constructor Summary
TimeoutLockAcquiringStrategy()
           
 
Method Summary
protected  boolean lockIt(Lock l)
          Subclasses implement this to lock the given lock.
 void setTimeoutMSecs(long timeoutMSecs)
          Set a new timeout value in milliseconds.
 
Methods inherited from class org.entityfs.lock.impl.AbstractLockAcquiringStrategy
getEntityLock, getLock, getReadLock, getWriteLock
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.entityfs.lock.LockAcquiringStrategy
getEntityLock, getLock, getReadLock, getWriteLock
 

Field Detail

INSTANCE

public static final TimeoutLockAcquiringStrategy INSTANCE
Constructor Detail

TimeoutLockAcquiringStrategy

public TimeoutLockAcquiringStrategy()
Method Detail

lockIt

protected boolean lockIt(Lock l)
                  throws InterruptedException
Description copied from class: AbstractLockAcquiringStrategy
Subclasses implement this to lock the given lock.

Specified by:
lockIt in class AbstractLockAcquiringStrategy
Parameters:
l - The lock.
Returns:
true if successful, false otherwise. When false is returned, it is interpreted as due to a timeout.
Throws:
InterruptedException - If the thread is interrupted while trying to acquire the lock.

setTimeoutMSecs

public final void setTimeoutMSecs(long timeoutMSecs)
Set a new timeout value in milliseconds. This does not change the timeout value for threads already waiting for a lock.

Parameters:
timeoutMSecs - The timeout time in milliseconds.