peerMap - the map between the existing peer objects
and their associated targets
toolkitThreadBusy - whether the toolkit thread
is waiting for a new native event to appear in its queue
or is dispatching an event
busyThreadSet - a set of all the event dispatch
threads that are busy at this moment, i.e. those that are not
waiting for a new event to appear in their event queue.
AWT is considered to be in ready-to-shutdown state when
peerMap is empty and toolkitThreadBusy
is false and busyThreadSet is empty.
The internal AWTAutoShutdown logic secures that the single non-daemon
thread (blockerThread) is running when AWT is not in
ready-to-shutdown state. This blocker thread is to prevent AWT from
exiting since the toolkit thread is now daemon and all the event
dispatch threads are started only when needed. Once it is detected
that AWT is in ready-to-shutdown state this blocker thread waits
for a certain timeout and if AWT state doesn't change during timeout
this blocker thread terminates all the event dispatch threads and
exits.
| Modifier and Type | Field and Description |
|---|---|
| private final Object | activationLock
This lock object is to secure that when a new blocker thread is started it will be the first who acquire the main lock after the thread that created the new blocker released the main lock by calling lock.wait() to wait for the blocker to start. |
| private Thread | blockerThread
References the alive non-daemon thread that is currently used for keeping AWT from exiting. |
| private final Set | busyThreadSet
This set keeps references to all the event dispatch threads that are busy at this moment, i.e. those that are not waiting for a new event to appear in their event queue. |
| private final Object | mainLock
This lock object is used to synchronize shutdown operations. |
| private final Map | peerMap
This is a map between components and their peers. |
| private static final int | SAFETY_TIMEOUT
Once we detect that AWT is ready to shutdown we wait for a certain timeout to pass before stopping event dispatch threads. |
| private static final AWTAutoShutdown | |
| private boolean | timeoutPassed
We need this flag to secure that AWT state hasn't changed while we were waiting for the safety timeout to pass. |
| private boolean | toolkitThreadBusy
Indicates whether the toolkit thread is waiting for a new native event to appear or is dispatching an event. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| pack-priv void | |
| public static AWTAutoShutdown | |
| pack-priv Object | |
| pack-priv static AWTEvent | |
| private boolean | Returns: true if AWT is in ready-to-shutdown state.Determine whether AWT is currently in ready-to-shutdown state. |
| pack-priv void | notifyPeerMapUpdated()
Notify that the peermap has been updated, that means a new peer has been created or some existing peer has been disposed. |
| public void | notifyThreadBusy(final Thread
thread to be added to this set, if not present. thread)Add a specified thread to the set of busy event dispatch threads. |
| public void | notifyThreadFree(final Thread
thread to be removed from this set, if present. thread)Remove a specified thread from the set of busy event dispatch threads. |
| public static void | notifyToolkitThreadBusy()
Notify that the toolkit thread is not waiting for a native event to appear in its queue. |
| public static void | notifyToolkitThreadFree()
Notify that the toolkit thread is waiting for a native event to appear in its queue. |
| pack-priv void | |
| public void | |
| private void | setToolkitBusy(final boolean
true if the toolkit thread state changes from idle
to busy. busy)Notify about the toolkit thread state change. |
| pack-priv void |
| activationLock | back to summary |
|---|---|
| private final Object activationLock This lock object is to secure that when a new blocker thread is started it will be the first who acquire the main lock after the thread that created the new blocker released the main lock by calling lock.wait() to wait for the blocker to start. | |
| blockerThread | back to summary |
|---|---|
| private Thread blockerThread References the alive non-daemon thread that is currently used for keeping AWT from exiting. | |
| busyThreadSet | back to summary |
|---|---|
| private final Set<Thread> busyThreadSet This set keeps references to all the event dispatch threads that are busy at this moment, i.e. those that are not waiting for a new event to appear in their event queue. Access is synchronized on the main lock object. | |
| mainLock | back to summary |
|---|---|
| private final Object mainLock This lock object is used to synchronize shutdown operations. | |
| peerMap | back to summary |
|---|---|
| private final Map<Object, Object> peerMap This is a map between components and their peers. we should work with in under activationLock&mainLock lock. | |
| SAFETY_TIMEOUT | back to summary |
|---|---|
| private static final int SAFETY_TIMEOUT Once we detect that AWT is ready to shutdown we wait for a certain timeout to pass before stopping event dispatch threads. | |
| theInstance | back to summary |
|---|---|
| private static final AWTAutoShutdown theInstance | |
| timeoutPassed | back to summary |
|---|---|
| private boolean timeoutPassed We need this flag to secure that AWT state hasn't changed while we were waiting for the safety timeout to pass. | |
| toolkitThreadBusy | back to summary |
|---|---|
| private boolean toolkitThreadBusy Indicates whether the toolkit thread is waiting for a new native event to appear or is dispatching an event. | |
| AWTAutoShutdown | back to summary |
|---|---|
| private AWTAutoShutdown() Constructor method is intentionally made private to secure a single instance. Use getInstance() to reference it.
| |
| activateBlockerThread | back to summary |
|---|---|
| private void activateBlockerThread() Creates and starts a new blocker thread. Doesn't return until the new blocker thread starts. | |
| dumpPeers | back to summary |
|---|---|
| pack-priv void dumpPeers(final PlatformLogger aLog) | |
| getInstance | back to summary |
|---|---|
| public static AWTAutoShutdown getInstance() Returns reference to a single AWTAutoShutdown instance. | |
| getPeer | back to summary |
|---|---|
| pack-priv Object getPeer(final Object target) | |
| getShutdownEvent | back to summary |
|---|---|
| pack-priv static AWTEvent getShutdownEvent() | |
| isReadyToShutdown | back to summary |
|---|---|
| private boolean isReadyToShutdown() Determine whether AWT is currently in ready-to-shutdown state.
AWT is considered to be in ready-to-shutdown state if
| |
| notifyPeerMapUpdated | back to summary |
|---|---|
| pack-priv void notifyPeerMapUpdated() Notify that the peermap has been updated, that means a new peer has been created or some existing peer has been disposed.
| |
| notifyThreadBusy | back to summary |
|---|---|
| public void notifyThreadBusy(final Thread thread) Add a specified thread to the set of busy event dispatch threads. If this set already contains the specified thread or the thread is null, the call leaves this set unchanged and returns silently.
| |
| notifyThreadFree | back to summary |
|---|---|
| public void notifyThreadFree(final Thread thread) Remove a specified thread from the set of busy event dispatch threads. If this set doesn't contain the specified thread or the thread is null, the call leaves this set unchanged and returns silently.
| |
| notifyToolkitThreadBusy | back to summary |
|---|---|
| public static void notifyToolkitThreadBusy() Notify that the toolkit thread is not waiting for a native event to appear in its queue. | |
| notifyToolkitThreadFree | back to summary |
|---|---|
| public static void notifyToolkitThreadFree() Notify that the toolkit thread is waiting for a native event to appear in its queue. | |
| registerPeer | back to summary |
|---|---|
| pack-priv void registerPeer(final Object target, final Object peer) | |
| run | back to summary |
|---|---|
| public void run() Implements java. Implementation of the Runnable interface. Encapsulates the blocker thread functionality.
| |
| setToolkitBusy | back to summary |
|---|---|
| private void setToolkitBusy(final boolean busy) Notify about the toolkit thread state change.
| |
| unregisterPeer | back to summary |
|---|---|
| pack-priv void unregisterPeer(final Object target, final Object peer) | |