Package edu.wisc.ssec.mcidasv.util.gui
Class EventDispatchThreadHangMonitor
java.lang.Object
java.awt.EventQueue
edu.wisc.ssec.mcidasv.util.gui.EventDispatchThreadHangMonitor
Monitors the AWT event dispatch thread for events that take longer than
a certain time to be dispatched.
The principle is to record the time at which we start processing an event,
and have another thread check frequently to see if we're still processing.
If the other thread notices that we've been processing a single event for
too long, it prints a stack trace showing what the event dispatch thread
is doing, and continues to time it until it finally finishes.
This is useful in determining what code is causing your Java application's
GUI to be unresponsive.
The original blog can be found here
Automatically detecting AWT event dispatch thread hangs
- Author:
- Elliott Hughes invalid input: '<'enh@jessies.org> Advice, bug fixes, and test cases from Alexander Potochkin and Oleg Sukhodolsky. https://swinghelper.dev.java.net/
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classprivate classprivate static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final longprivate final LinkedList<EventDispatchThreadHangMonitor.DispatchInfo> private static intprivate booleanprivate static final EventDispatchThreadHangMonitorprivate static final org.slf4j.Loggerprivate static final long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidprotected voiddispatchEvent(AWTEvent event) Overrides EventQueue.dispatchEvent to call our pre and post hooks either side of the system's event dispatch code.private static intstatic voidSets up hang detection for the event dispatch thread.private voidSets up a timer to check for hangs frequently.static voidprivate voidStops tracking a dispatch.private voidStarts tracking a dispatch.private static StringstackTraceToString(StackTraceElement[] stackTrace) Methods inherited from class java.awt.EventQueue
createSecondaryLoop, getCurrentEvent, getMostRecentEventTime, getNextEvent, invokeAndWait, invokeLater, isDispatchThread, peekEvent, peekEvent, pop, postEvent, push
-
Field Details
-
logger
-
INSTANCE
-
CHECK_INTERVAL_MS
- See Also:
-
UNREASONABLE_DISPATCH_DURATION_MS
- See Also:
-
hangCount
-
haveShownSomeComponent
-
dispatches
-
-
Constructor Details
-
EventDispatchThreadHangMonitor
private EventDispatchThreadHangMonitor()
-
-
Method Details
-
initTimer
Sets up a timer to check for hangs frequently. -
initMonitoring
Sets up hang detection for the event dispatch thread. -
dispatchEvent
Overrides EventQueue.dispatchEvent to call our pre and post hooks either side of the system's event dispatch code.- Overrides:
dispatchEventin classEventQueue
-
preDispatchEvent
Starts tracking a dispatch. -
postDispatchEvent
Stops tracking a dispatch. -
checkForDeadlock
-
stackTraceToString
-
getNewHangNumber
-
main
-