jodd.util
Class MutexSync
java.lang.Object
jodd.util.MutexSync
- public class MutexSync
- extends java.lang.Object
The very same Mutex, with lockTry() method added. This method locks a
mutex if mutex is currently unlocked and returns true. If mutex was
previously locked, it will not wait for its releasing: instead, it will
just return false.
Since both lock() and lockTry() methods are synchronized, lockTry() can
not returns the faked 'true' which indicates that mutex was availiable and
locked, while this is not true and while another thread has meanwhile
locked the mutex. But, the opposite situation can happend: lockTry() may
return faked 'false' which indicated that mutex is in use, while meanwhile
another thread that has a lock may release it. However, this situations
occurs very, very rare and, on the other hand, this situation is not
harmful for the application.
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
MutexSync
public MutexSync()
- Constructor.
lock
public void lock()
lockTry
public boolean lockTry()
- If Mutex is locked, returns false.
If Mutex is unlocked, it locks it and returns true.
- Returns:
- true if mutex has been locked, false otherwise.
unlock
public void unlock()
isLocked
public boolean isLocked()
Jodd v0.24.5 Javadoc