Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to have two timers?

 
Curtis Hoffmann
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).

Thanks.

(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.)
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Curtis Hoffmann
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!