Package de.mhus.lib.core.concurrent
Class Lock
- java.lang.Object
-
- de.mhus.lib.core.concurrent.Lock
-
- Direct Known Subclasses:
ThreadLock
public class Lock extends Object
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ThreadgetLocker()longgetLockTime()StringgetName()booleanisLocked()booleanisPrivacy()voidlock()booleanlock(long timeout)voidlock(Runnable task)Run the given task in a locked environment.voidlock(Runnable task, long timeout)Run the given task in a locked environment.protected voidlockEvent(boolean locked)Overwrite this to get the lock events.voidlockWithException(long timeout)protected voidregister()booleanrelease()A synonym to unlock()voidsetName(String name)StringtoString()booleanunlock()Unlock if the current thread is also the owner.voidunlockHard()Unlock in every case !!! This can break a locked area.voidwaitUntilUnlock()Sleeps until the lock is released.booleanwaitUntilUnlock(long timeout)voidwaitWithException(long timeout)
-
-
-
Method Detail
-
register
protected void register()
-
lock
public void lock()
-
lockEvent
protected void lockEvent(boolean locked)
Overwrite this to get the lock events.- Parameters:
locked-
-
lockWithException
public void lockWithException(long timeout)
-
lock
public boolean lock(long timeout)
-
lock
public void lock(Runnable task)
Run the given task in a locked environment.- Parameters:
task-
-
lock
public void lock(Runnable task, long timeout)
Run the given task in a locked environment.- Parameters:
task-timeout-
-
unlock
public boolean unlock()
Unlock if the current thread is also the owner.- Returns:
- true if unlock was successful
-
release
public boolean release()
A synonym to unlock()- Returns:
- true if unlock was successful
-
unlockHard
public void unlockHard()
Unlock in every case !!! This can break a locked area.
-
waitUntilUnlock
public void waitUntilUnlock()
Sleeps until the lock is released.
-
waitWithException
public void waitWithException(long timeout)
-
waitUntilUnlock
public boolean waitUntilUnlock(long timeout)
-
isLocked
public boolean isLocked()
-
getName
public String getName()
-
setName
public void setName(String name)
-
getLocker
public Thread getLocker()
-
isPrivacy
public boolean isPrivacy()
-
getLockTime
public long getLockTime()
-
-