Skip to main content

Writing responsive user interfaces?

3 replies [Last post]
h.buerger
Offline
Joined: 2006-02-17
Points: 0

My problem is not related to SWING it's the garbage collector. I need a lot of memory to hold my models and the application stops while doing a full garbage collection. It is really annoying that menues don't pop up, panes jump and everything works jumpy. Is there any chance to get rid of these interrupts and to create a responsive application?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
karsten
Offline
Joined: 2003-06-11
Points: 0

Sun's virtual machines provide different garbage collectors and a bunch of settings to tweak them. Among other things, you can adjust the GC's maximum pause time, footprint, and throughput. At least make sure you're using the appropriate GC algorithm. For details see http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html

I provide an application that often hold models that consume over 100MB of data - however, the app feels quite responsive. I use a couple of techniques to improve the responsiveness [i]and[/i] startup time. For example, I "prepare" popup menus and layout in a background thread, so the classes are loaded and HotSpot may have touched them, before they get used by the users. Besides the general GC tuning tips this may help you too. Here's the app: http://www.jgoodies.com/freeware/jdiskreport/index.html

Anyway, switching to a concurrent low pause GC may satisfy you.

Regards,
Karsten Lentzsch

h.buerger
Offline
Joined: 2006-02-17
Points: 0

Thanks for the tips. I tried the version 5.0 and it got better. I could drop the down times below 500ms on my very fast development box.
One thing I experienced was that the low pause collector (-XX:+UseConcMarkSweepGC) makes things worse. Using the server VM (-server) helps. The -XX:MaxGCPauseMillis=50 flag doesn't help really. Everything based on my scenario, the whole issue heavily depends on the number and size of objects.
But the problem is still there. Create a screen saver with java and add a random sleep(50ms) to it, it will annoy you! Change that to 500ms and you'll throw it away.
A TV has about 25 prictures a second, that means 40ms per picture. Thats neccessary to create a floating movement on the screen. Even the new SUN JVM 5.0 is still not able to do that with large heaps. Writing an editor with smooth scrolling is not possible.
Somebody created a real time garbage collector using the IBM JVM but this one is not commercially available :-(

karsten
Offline
Joined: 2003-06-11
Points: 0

Haug,

I understand that it may be difficult to tweak the GC for your case. But the good news is, that one [b]can[/b] build responsive Java desktop applications. I do real-time animations in Java that use advanced rendering techniques, including translucency and fancy font effects - all which works well.

You may experiment with GC types and settings using the Java2demo that ships with each Sun JDK in the demos folder. You can then easily see how long the GC interrupts the animations.

I suggest that you profile your application to learn about the data held and the hot spots that seem to consume so much time in your configuration. That may help you further tweak the GC - if this is necessary at all.

Hope this helps. Best regards,
Karsten