|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.refractions.udig.ui.UDIGDisplaySafeLock
public class UDIGDisplaySafeLock
This lock is reentrant and guarantees that a display thread will not block,
it will continue to call Display#readAndDispatch()
. The Display thread
gets priority over non-display threads.
API is copied from the ReentrantLock
Constructor Summary | |
---|---|
UDIGDisplaySafeLock()
|
Method Summary | |
---|---|
int |
getHoldCount()
Queries the number of holds on this lock by the current thread. |
int |
getWaitQueueLength(java.util.concurrent.locks.Condition condition)
Returns an estimate of the number of threads waiting on the given condition associated with this lock. |
boolean |
hasWaiters(java.util.concurrent.locks.Condition condition)
Queries whether any threads are waiting on the given condition associated with this lock. |
protected void |
init()
|
boolean |
isHeldByCurrentThread()
Queries if this lock is held by the current thread. |
boolean |
isLocked()
Returns true if locked by a different thread. |
void |
lock()
|
void |
lockInterruptibly()
|
java.util.concurrent.locks.Condition |
newCondition()
|
boolean |
tryLock()
|
boolean |
tryLock(long timeout,
java.util.concurrent.TimeUnit unit)
|
void |
unlock()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public UDIGDisplaySafeLock()
Method Detail |
---|
protected void init()
public int getHoldCount()
A thread has a hold on a lock for each lock action that is not matched by an unlock action.
The hold count information is typically only used for testing and debugging purposes. For example, if a certain section of code should not be entered with the lock already held then we can assert that fact:
class X { ReentrantLock lock = new ReentrantLock(); // ... public void m() { assert lock.getHoldCount() == 0; lock.lock(); try { // ... method body } finally { lock.unlock(); } } }
public int getWaitQueueLength(java.util.concurrent.locks.Condition condition)
condition
- the condition
java.lang.IllegalMonitorStateException
- if this lock
is not held
java.lang.IllegalArgumentException
- if the given condition is
not associated with this lock
java.lang.NullPointerException
- if condition nullpublic boolean hasWaiters(java.util.concurrent.locks.Condition condition)
condition
- the condition
java.lang.IllegalMonitorStateException
- if this lock
is not held
java.lang.IllegalArgumentException
- if the given condition is
not associated with this lock
java.lang.NullPointerException
- if condition nullpublic boolean isHeldByCurrentThread()
Analogous to the Thread.holdsLock(java.lang.Object)
method for built-in
monitor locks, this method is typically used for debugging and
testing. For example, a method that should only be called while
a lock is held can assert that this is the case:
class X { ReentrantLock lock = new ReentrantLock(); // ... public void m() { assert lock.isHeldByCurrentThread(); // ... method body } }
It can also be used to ensure that a reentrant lock is used in a non-reentrant manner, for example:
class X { ReentrantLock lock = new ReentrantLock(); // ... public void m() { assert !lock.isHeldByCurrentThread(); lock.lock(); try { // ... method body } finally { lock.unlock(); } } }
public boolean isLocked()
public void lock()
lock
in interface java.util.concurrent.locks.Lock
public void lockInterruptibly() throws java.lang.InterruptedException
lockInterruptibly
in interface java.util.concurrent.locks.Lock
java.lang.InterruptedException
public java.util.concurrent.locks.Condition newCondition()
newCondition
in interface java.util.concurrent.locks.Lock
public boolean tryLock()
tryLock
in interface java.util.concurrent.locks.Lock
public boolean tryLock(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
tryLock
in interface java.util.concurrent.locks.Lock
java.lang.InterruptedException
public void unlock()
unlock
in interface java.util.concurrent.locks.Lock
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |