| Pseudo-lock that allows code to be synchronized with the AWT event dispatch thread.
This is handy in that you can define a constant of type Lock in some API, initially
set to a normal lock, and then switch everything to the event thread (or vice-versa).
It behaves somewhat differently from a read-write lock.
- There is no distinction between read and write access. There is only one
access mode, which is exclusive, and runs on the AWT thread, not in the
caller thread.
- There is no
PrivilegedLock , so you cannot make entry or exit calls
by themselves (which would make no sense).
- You cannot specify a level. The event lock is considered to be at a higher
level than any ordinary lock with a defined level. This means that from the
event thread, you can enter any lock (subject to other restrictions), but
while holding any ordered lock you may not block on the event thread
(using
Locks.eventLock methods).
-
Lock.read(LockAction) ,
Lock.read(LockExceptionAction) ,
Lock.write(LockAction) ,
Lock.write(LockExceptionAction) ,
Lock.read(Runnable) , and
Lock.write(Runnable) when called from the
event thread run synchronously. Else they all block, like
java.awt.EventQueue.invokeAndWait .
-
Lock.readLater(Runnable) and
Lock.writeLater(Runnable) run asynchronously, like
java.awt.EventQueue.invokeLater .
-
Lock.canRead and
Lock.canWrite just test whether you are in the event
thread, like
java.awt.EventQueue.isDispatchThread .
|