java - How to report AWT/Swing event queue length programmatically? -


ideally, answer platform independent, platform specific, particularly oracle jvms, useful well. project i'm working on still running version 6 jvm.

the particular need has gui "freezing" time time. i'm aware of doing on gui work on edt. program working on windows, after moving linux, these "strange" gui issues began happen. actually, issue has occurred on 2 applications, both after windows linux move. jvisualvm shows on 10 million java.awt.eventqueueitem objects. suspicion awt queue growing faster it's being served on linux, idea put awt queue length indicator on app , see shows queue grows/shrinks.

a bit of googling found this, linear scan of queue. maybe there's better way?

interesting subject. i've investigated eventqueue code bit, , while haven't solved problem, may have useful pointers:

  1. oracle's implementation of eventqueue doesn't keep size variable, unless take on complete control of eventqueue (see 3), there's no way you're going better linear scan of queue when using oracle's jre.
  2. you can write you're own eventqueue (probably copy-pasting oracle's implementation plus tweaking** easiest) , use eventqueue.push(eventqueue) install own implementation. events in queue transferred queue, can count them posted queue. unfortunately, still linear scan, @ least it's platform independent.
  3. alternatively, install own eventqueue implementation (see 2) possible after original event queue has been created (do in static code block @ start of class contains main method). then, implementation can count events posted , don't have scan queue when want know size. you'll have hope no 1 else pushes own eventqueue on top of yours ;)

** tweaking: haven't tried this, strip public/protected static code (everyone references methods/variables uses java.awt.eventqueue anyway, , can you), add size variable , update variable in following 4 methods: postevent(awtevent, int), getnexteventprivate(), getnextevent(int) , removesourceevent(object, boolean).

a big issue modification fact eventqueue makes calls awt methods default visibility (for example, toolkit.geteventqueue() , component.getaccesscontrolcontext()), not allowed call since implementation in different package. you'll have find workaround each case individually.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -