Ideally, the answer will be platform independent, but platform specific, particularly Oracle JVMs, are useful as well. The project that I'm working on is still running a version 6 JVM.
The particular need has to do with a GUI that is "freezing" from time to time. I'm well aware of doing on GUI work on the EDT. The program was working well on Windows, but after moving to Linux, these "strange" GUI issues began to happen. Actually, this issue has occurred on two applications, both after a Windows to Linux move. JVisualVM shows over 10 million java.awt.EventQueueItem
objects. The suspicion is that the AWT queue is growing faster than it's being served on Linux, so the idea is to put an AWT queue length indicator on the app and see what it shows as the queue grows/shrinks.
A bit of Googling found this, but it does a linear scan of the queue. Maybe there's some better way?
Interesting subject. I've investigated the EventQueue code a bit, and while I haven't solved your problem, I may have some useful pointers:
EventQueue.push(EventQueue)
to install your own implementation. All events in the queue will be transferred to your queue, so you can count them as they are posted to your queue. Unfortunately, this is still a linear scan, but at least now it's platform independent.** Some tweaking: I haven't tried this, but I would strip all public/protected static code (everyone that references those methods/variables uses java.awt.EventQueue anyway, and so can you), add the size variable and update this variable in the following four methods: postEvent(AWTEvent, int)
, getNextEventPrivate()
, getNextEvent(int)
and removeSourceEvent(Object, boolean)
.
A big issue with this modification is the fact that the EventQueue makes some calls to AWT methods with default visibility (for example, Toolkit.getEventQueue()
and Component.getAccessControlContext()
), which you are not allowed to call since your implementation will be in a different package. You'll have to find a workaround for each case individually.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With