How to check if your code is running on the Java Event Dispatch Thread

How to check if your code is running on the Java Event Dispatch Thread



Many times we need to check whether code is running on the Java Event Dispatch thread or not ?
We can use static method of the SwingUtilities class if we are not sure if code is running on the event dispatching thread of not.
Following code shows simple check we can have using static method of SwingUtilities class.


if (SwingUtilities.isEventDispatchThread())
{
System.err.println("In event dispatching thread");
}
else
{
System.err.println("Not an event dispatching thread");
}
Share on Google Plus

About Pranav

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment