|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.openmdx.base.concurrent.locks.jre.before1_5.SimpleLock
public class SimpleLock
openMDX' Simple Lock Implementaton relies on its Java
synchronization methods.
You must not
synchronize statement
wait() methods
notify() method
notifyAll() method
| Constructor Summary | |
|---|---|
SimpleLock()
|
|
| Method Summary | |
|---|---|
void |
lock()
Acquires the lock. |
void |
lockInterruptibly()
Acquires the lock unless the current thread is interrupted. |
Condition |
newCondition()
Returns a new Condition instance that is bound to this
Lock instance. |
boolean |
tryLock()
Acquires the lock only if it is free at the time of invocation. |
boolean |
tryLock(long time,
TimeUnit unit)
Acquires the lock if it is free within the given waiting time and the current thread has not been interrupted. |
void |
unlock()
Releases the lock. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public SimpleLock()
| Method Detail |
|---|
public void lock()
LockIf the lock is not available then the current thread becomes disabled for thread scheduling purposes and lies dormant until the lock has been acquired.
Implementation Considerations
A Lock implementation may be able to detect erroneous use of the lock, such as an invocation that would cause deadlock, and may throw an (unchecked) exception in such circumstances. The circumstances and the exception type must be documented by that Lock implementation.
lock in interface Lock
public void lockInterruptibly()
throws InterruptedException
Lockinterrupted.
Acquires the lock if it is available and returns immediately.
If the lock is not available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of two things happens:
interrupts the current
thread, and interruption of lock acquisition is supported.
If the current thread:
interrupted while acquiring
the lock, and interruption of lock acquisition is supported,
InterruptedException is thrown and the current thread's
interrupted status is cleared.
Implementation Considerations
The ability to interrupt a lock acquisition in some implementations may not be possible, and if possible may be an expensive operation. The programmer should be aware that this may be the case. An implementation should document when this is the case.
An implementation can favor responding to an interrupt over normal method return.
A Lock implementation may be able to detect erroneous use of the lock, such as an invocation that would cause deadlock, and may throw an (unchecked) exception in such circumstances. The circumstances and the exception type must be documented by that Lock implementation.
lockInterruptibly in interface LockInterruptedException - if the current thread is interrupted
while acquiring the lock (and interruption of lock acquisition is
supported).Thread.interrupt()public Condition newCondition()
LockCondition instance that is bound to this
Lock instance.
Before waiting on the condition the lock must be held by the
current thread.
A call to Condition.await() will atomically release the lock
before waiting and re-acquire the lock before the wait returns.
Implementation Considerations
The exact operation of the Condition instance depends on the
Lock implementation and must be documented by that
implementation.
newCondition in interface LockCondition instance for this Lock
instance.public boolean tryLock()
LockAcquires the lock if it is available and returns immediately with the value true. If the lock is not available then this method will return immediately with the value false.
A typical usage idiom for this method would be:
Lock lock = ...;
if (lock.tryLock()) {
try {
// manipulate protected state
} finally {
lock.unlock();
}
} else {
// perform alternative actions
}
This usage ensures that the lock is unlocked if it was acquired, and
doesn't try to unlock if the lock was not acquired.
tryLock in interface Lock
public boolean tryLock(long time,
TimeUnit unit)
throws InterruptedException
Lockinterrupted.
If the lock is available this method returns immediately with the value true. If the lock is not available then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of three things happens:
interrupts the current
thread, and interruption of lock acquisition is supported; or
If the lock is acquired then the value true is returned.
If the current thread:
interrupted while acquiring
the lock, and interruption of lock acquisition is supported,
InterruptedException is thrown and the current thread's
interrupted status is cleared.
If the specified waiting time elapses then the value false is returned. If the time is less than or equal to zero, the method will not wait at all.
Implementation Considerations
The ability to interrupt a lock acquisition in some implementations may not be possible, and if possible may be an expensive operation. The programmer should be aware that this may be the case. An implementation should document when this is the case.
An implementation can favor responding to an interrupt over normal method return, or reporting a timeout.
A Lock implementation may be able to detect erroneous use of the lock, such as an invocation that would cause deadlock, and may throw an (unchecked) exception in such circumstances. The circumstances and the exception type must be documented by that Lock implementation.
tryLock in interface Locktime - the maximum time to wait for the lockunit - the time unit of the time argument.
InterruptedException - if the current thread is interrupted
while acquiring the lock (and interruption of lock acquisition is
supported).Thread.interrupt()public void unlock()
LockImplementation Considerations
A Lock implementation will usually impose restrictions on which thread can release a lock (typically only the holder of the lock can release it) and may throw an (unchecked) exception if the restriction is violated. Any restrictions and the exception type must be documented by that Lock implementation.
unlock in interface Lock
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||