Groovy Documentation

org.jdesktop.swinghelper.debug
[Java] Class EventDispatchThreadHangMonitor

java.lang.Object
  java.awt.EventQueue
      org.jdesktop.swinghelper.debug.EventDispatchThreadHangMonitor

public final class EventDispatchThreadHangMonitor
extends EventQueue

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

Authors:
Elliott Hughes

Advice, bug fixes, and test cases from Alexander Potochkin and Oleg Sukhodolsky.

https://swinghelper.dev.java.net/


Nested Class Summary
private static class EventDispatchThreadHangMonitor.DispatchInfo

private class EventDispatchThreadHangMonitor.HangChecker

 
Field Summary
private static long CHECK_INTERVAL_MS

private static EventDispatchThreadHangMonitor INSTANCE

private static org.slf4j.Logger LOG

private static long UNREASONABLE_DISPATCH_DURATION_MS

private LinkedList dispatches

private static int hangCount

private boolean haveShownSomeComponent

private long timeout

 
Constructor Summary
EventDispatchThreadHangMonitor()

 
Method Summary
private def EventDispatchThreadHangMonitor()

private static void checkForDeadlock()

protected void dispatchEvent(AWTEvent event)

Overrides EventQueue.dispatchEvent to call our pre and post hooks either side of the system's event dispatch code.

static EventDispatchThreadHangMonitor getInstance()

private static int getNewHangNumber()

long getTimeout()

static void initMonitoring()

Sets up hang detection for the event dispatch thread.

private void initTimer()

Sets up a timer to check for hangs frequently.

private void postDispatchEvent()

Stops tracking a dispatch.

private void preDispatchEvent()

Starts tracking a dispatch.

void setTimeout(long timeout)

private static String stackTraceToString(StackTraceElement[] stackTrace)

 
Methods inherited from class EventQueue
push, postEvent, isDispatchThread, invokeLater, getMostRecentEventTime, getCurrentEvent, invokeAndWait, getNextEvent, peekEvent, peekEvent, wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Field Detail

CHECK_INTERVAL_MS

private static final long CHECK_INTERVAL_MS


INSTANCE

private static final EventDispatchThreadHangMonitor INSTANCE


LOG

private static final org.slf4j.Logger LOG


UNREASONABLE_DISPATCH_DURATION_MS

private static final long UNREASONABLE_DISPATCH_DURATION_MS


dispatches

private final LinkedList dispatches


hangCount

private static int hangCount


haveShownSomeComponent

private boolean haveShownSomeComponent


timeout

private long timeout


 
Constructor Detail

EventDispatchThreadHangMonitor

EventDispatchThreadHangMonitor()


 
Method Detail

EventDispatchThreadHangMonitor

private def EventDispatchThreadHangMonitor()


checkForDeadlock

private static void checkForDeadlock()


dispatchEvent

@Override
protected void dispatchEvent(AWTEvent event)
Overrides EventQueue.dispatchEvent to call our pre and post hooks either side of the system's event dispatch code.


getInstance

public static EventDispatchThreadHangMonitor getInstance()


getNewHangNumber

private static int getNewHangNumber()


getTimeout

public long getTimeout()


initMonitoring

public static void initMonitoring()
Sets up hang detection for the event dispatch thread.


initTimer

private void initTimer()
Sets up a timer to check for hangs frequently.


postDispatchEvent

private void postDispatchEvent()
Stops tracking a dispatch.


preDispatchEvent

private void preDispatchEvent()
Starts tracking a dispatch.


setTimeout

public void setTimeout(long timeout)


stackTraceToString

private static String stackTraceToString(StackTraceElement[] stackTrace)


 

Groovy Documentation