This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to have two timers?  RSS feed

 
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!