How do I profile the EDT in Swing?

后端 未结 3 456
隐瞒了意图╮
隐瞒了意图╮ 2021-02-01 11:31

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 sometime

3条回答
  •  日久生厌
    2021-02-01 11:46

    Take a look at this question. It describes a simple log on the EDT.

    Create a class like this:

    public class TimedEventQueue extends EventQueue {
        @Override
        protected void dispatchEvent(AWTEvent event) {
            long startNano = System.nanoTime();
            super.dispatchEvent(event);
            long endNano = System.nanoTime();
    
            if (endNano - startNano > 50000000)
                System.out.println(((endNano - startNano) / 1000000)+"ms: "+event);
        }
    }
    

    Then replace the default EventQueue with the custom class:

    Toolkit.getDefaultToolkit().getSystemEventQueue().push(new TimedEventQueue());
    

提交回复
热议问题