>I need to create an interactive animation with smooth playback in Java 2D.
>The performance of Java 2D seems quite good in general, so I can easily use
>this API to achieve the framerate I need.
>
>But my concern is that playback is jerky. The computer halts quite often
>when showing the animation. Even the simplest animation, say of a small
>ball moving across the screen, will not move smoothly. It will move
>smoothly for a second or two, then jerk, then move smoothly again. I have
>tried many approaches to get rid of this jerky movement, but failed. The
>problem seems to be deeply buried in the JVM itself, and I suspect what is
>going on is very frequent garbage collection of garbage created by the JVM
>itself. I have noticed this same behavior in all Java 2D related examples,
>also the examples from Sun. My old Java applets also suffer the same
>problem when running in a Java 2 environment, even though they ran smoothly
>in previous Java environments.
>
>I recognize Java 2D as a powerful API for multimedia production, but if it
>does not allow smooth playback the usefulness is drastically lowered. I
>hope I do not need to return to a previous Java version to solve the problem.
>
>Does anyone have any experience or thoughts about this?
My "Waves" benchmark, which continuously applies a sine wave to the
x-coordinates of an image, seems to run smoothly with Java 2, but it's up
to 5 times slower compared to JDK 1.1.7. To run the benchmark, start my
ImageJ program (http://rsb.info.nih.gov/ij/), open a sample image using
File/Open, and then use the Image/Benchmarks/Waves command. As an
experiment, try moving the Memory Monitor window (Plug-Ins/Monitor Memory)
over the the image being animated. With Java 2, notice how the the flat
memory utilization curve changes to a sawtooth, indicating increased
garbage collection.
Here are the frame rates I get using a 512x512 image on a P2/400 running
Windows 95.
JDK 1.1.7 JDK 1.2 Ratio
--------- ------- -----
RGB 19.4 11.7 1.6
RGB(1) 20.1 5.1 3.9
RGB(2) 18.8 9.1 2.1
RGB-D 14.4 2.9 5.0
RGB-D(1) 15.4 2.9 5.3
RGB-D(2) 14.6 2.8 5.2
8-bit color 25.7 25.5 1.0
8-bit color(1) 27.0 6.2 4.4
8-bit color(2) 24.6 18.3 1.3
8-bit grays 25.6 17.2 1.5
8-bit grays(1) 26.3 8.4 3.1
8-bit grays(2) 24.4 13.8 1.8
(1) Image partially covered by ImageJ window
(2) Image zoomed 2:1 and displayed in 512x512 window
RGB-D = RGB image using the default direct color model
You might also want to check out bug 4185726 (JDK 1.2 drawImage very slow
compared to JDK 1.1.7), the #1 bug on the bug parade.
-wayne