I'm using the Swing timer class, and it looks like when I have two different timer instances running that they clobber each other (the timing of the primary timer becomes erratic). Is there a way to set up two timers to run simultaneously and independently? (I'm using netbeans because I have a fairly extensive UI for this application, if it matters).
(The application is a synthesizer controller. One timer is for a metronome, and the other is an arpeggiator. So, they may be started at different times or run at different rates.)
Not using javax.swing.Timer, no. All instance of that class use a single shared thread for their timing behavior.
The java.util.Timer class on the other hand does provide every instance with its own thread.
There's a nice article on using Swing timers that explains their use in a bit more detail, and my guess is that you're using the wrong timer for the wrong job
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
posted 4 years ago
Jelle Klap wrote:my guess is that you're using the wrong timer for the wrong job
My guess is that you're right. Thanks for the pointer. I'll see what I can come up with.
You've gotta fight it! Don't give in! Read this tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user