I have a GUI and a loosely coupled object running on separate threads.
The JSlider on the GUI uses a ChangeListener to update a volatile variable on the object. The object consults this variable on a very frequent basis in a while loop (44100 times per second on average, as it is in the core of a sound playback routine, and consults once per frame).
Now, if the JVM doesn’t switch back and forth very often (I have an old Windows XP, Pentium 4, 3.2 GHz, 3GB RAM, so it it’s a simulated rather than a true multicore processing situation) then we have this happening: the volatile variable is updated as many as 10 times perhaps before the other thread is allowed to do anything, and thus the other thread sees a rather large jump because it only gets the last update.
Is there a way to alter the JVM to make it switch threads more often? Or is that a place one should not go? (Is it similar to the way one can tweak Garbage Collection frequency, perhaps?)
I suppose I could try to think in terms of putting the updates in a queue for consumption (so none are skipped). But I’ll also have to figure out how to spread them out. Dang. Is this what is normally done in such a situation? I can put more smoothing in the response to the slider, but that makes it rather laggy.