public final class

AWTAutoShutdown

extends Object
implements Runnable
java.lang.Object
   ↳ sun.awt.AWTAutoShutdown

Class Overview

This class is to let AWT shutdown automatically when a user is done with AWT. It tracks AWT state using the following parameters:

  • 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.

Summary

Public Methods
static AWTAutoShutdown getInstance()
Returns reference to a single AWTAutoShutdown instance.
void notifyThreadBusy(Thread thread)
Add a specified thread to the set of busy event dispatch threads.
void notifyThreadFree(Thread thread)
Remove a specified thread from the set of busy event dispatch threads.
static void notifyToolkitThreadBusy()
Notify that the toolkit thread is not waiting for a native event to appear in its queue.
static void notifyToolkitThreadFree()
Notify that the toolkit thread is waiting for a native event to appear in its queue.
void run()
Implementation of the Runnable interface.
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.lang.Runnable

Public Methods

public static AWTAutoShutdown getInstance ()

Returns reference to a single AWTAutoShutdown instance.

public void notifyThreadBusy (Thread thread)

Add a specified thread to the set of busy event dispatch threads. If this set already contains the specified thread, the call leaves this set unchanged and returns silently.

Parameters
thread thread to be added to this set, if not present.
See Also

public void notifyThreadFree (Thread thread)

Remove a specified thread from the set of busy event dispatch threads. If this set doesn't contain the specified thread, the call leaves this set unchanged and returns silently.

Parameters
thread thread to be removed from this set, if present.
See Also

public static void notifyToolkitThreadBusy ()

Notify that the toolkit thread is not waiting for a native event to appear in its queue.

See Also

public static void notifyToolkitThreadFree ()

Notify that the toolkit thread is waiting for a native event to appear in its queue.

See Also

public void run ()

Implementation of the Runnable interface. Incapsulates the blocker thread functionality.

See Also
  • AWTAutoShutdown#isReadyToShutdown