title: How to implement idle task in Java Swing
body: <p>I have a GUI app that is getting to be quite slow. I want to start introducing timing for various GUI tasks - however, many of our GUI actions trigger other actions which then "invoke later" to trigger other actions.</p>
  
  <p>Eventually, it all settles down and there's nothing more to do. At this time, I want to stop a timer and report how long that GUI "action" took.</p>
  
  <p>I figured the way to do this is to implement a method called <code>invokeOnceIdle(Runnable task)</code>. The method will execute the supplied task only once the AWTEventQueue is "empty". i.e. the supplied "task" should be the last thing in the queue.</p>
  
  <p>One way to do this would be is if there's a way to specify a "lowest" priority to <code>SwingUtilities.invokeLater</code> - but this isn't possible.</p>
  
  <p>I next looked to see if I could "invokeLater" a Runnable which checks to see if the event queue is "empty" - but there's no public way to see if the event queue is actually empty.</p>
  
  <p>What's the best way to do this?</p>