LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: elias4444 on February 08, 2006, 15:54:38

Title: Question about Timer and multiple threads
Post by: elias4444 on February 08, 2006, 15:54:38
How does Timer work exactly? I was wondering because I'm using it in two different threads simultaneously. I noticed that you have to call the static method Timer.tick(), and I was wondering if by calling that in one of the threads does that tick the clock in both?

Just wondering.
Title: Question about Timer and multiple threads
Post by: CaseyB on February 08, 2006, 16:25:10
I would think so.  Being that it's Static there is only 1 for every timer, that should hold true regardless of threading I would think, But, hey, I've been wrong before! :D
Title: Question about Timer and multiple threads
Post by: elias4444 on February 08, 2006, 16:43:12
Of course, I'm also wondering if my question is valid or not... does "ticking" the clock actually push it forward? Or does it simply update a pointer to the actual time? If the latter is the case, then it doesn't matter how many times you call Timer.tick().
Title: hmmmm...
Post by: Fool Running on February 08, 2006, 22:55:46
Quote from documentation:
QuoteGet the next time update from the system's hires timer. This method should be called once per main loop iteration; all timers are updated simultaneously from it.
It sounds like it just updates the time on the timers.
Title: Question about Timer and multiple threads
Post by: elias4444 on February 08, 2006, 23:31:57
Ah... I figured out my problem. Calling Timer.tick() doesn't hurt anything (even if you call it too often it appears). Turns out, my problem was using Thread.sleep(1). When I switched everything over to Thread.yield(), it all worked great. I think it has to do with the dedicated server sleeping, building up packets, and then sending them when it wakes back up. It was causing jitters for my clients.

Thanks for the replies everyone! I hope my experience helps someone out.