I have an application that I'm building in Swing. It has a scrollable and zoomable chart component which I can pan and zoom in. The whole thing is smooth except that sometimes the UI will pause for about 750 ms and I don't know why. This doesn't always happen - but sometimes something happens in the application and it starts pausing like this once every 6-8 seconds.
It seems pretty clear that there's some event being placed on the EDT that's taking 750 ms or so to run, which shouldn't be happening.
How do I profile the EDT specifically like this? What I would really like to do is get something that will output to a log or System.out every time an event runs on the EDT with the total amount of time the event took. Is there a way to do this?
Or is there some tool that will do this for me and give me a log of everything that runs on the EDT and how long it takes?
I'd like to go through this log, look at everything that's taking a long time, and find the problem.
I'd say it's likely this isn't actually something on the EDT but actually garbage collection.
Assuming that's the case I don't know of any solution I'm afraid. I've actually never written anything in Swing which didn't have this type of behavior occasionally.
To try & debug you could subclass EventQueue & install a new one using:
Toolkit.getDefaultToolkit().getSystemEventQueue().push(xxx);
This should allow you to at least see what events are being processed by the EDT.
Take a look at this question. It describes a simple log on the EDT.
Create a class like this:
Then replace the default EventQueue with the custom class:
Make sure you are running only GUI related operations in EDT and there are no long running tasks in EDT. There is one awesome tool called SwingExplorer it has one feature to monitor EDT operations. Hope this will help.