Is there any way to determine how many Runnables are currently queued in the EventQueue?... I mean the system EventQueue, i.e. all the Runnables to be run in the EDT. And mess with the queue, maybe?
What I want to do is to prioritise GUI Runnables... if a user-driven GUI event comes along it should be executed immediately, jumping the queue before any queued Runnables (which, by the way, are all going to be concerned with modifying non-visible Swing components. NB latest Swing guidelines: ALL Swing components must be changed on the EDT, even if hidden).
There are possibilities for a simple, contrived queue with "urgent" and "non-urgent" Runnables: each Runnable could increment an "observable" AtomicInteger counter, and then the execution of each could decrement it... and a BlockingQueue would ensure that non-urgent Runnables would only be submitted to "invokeLater" if the BlockingQueue size changed down to 1 (or 2 or 0 perhaps). Instinct makes me think such an arrangement would introduce quite a bit of latency though.
Plus it'd be nicer to be able to interfere with the EDT's own queue directly. Should I maybe roll my own EDT queue? Is that possible?
NB obviously observation of the state of the EDT queue (or intervention on it) would have to be done from a non-EDT thread. There may be "thread visibility" issues for all I know...