Question about Timer and multiple threads

Started by elias4444, February 08, 2006, 15:54:38

Previous topic - Next topic

elias4444

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.
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

CaseyB

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

elias4444

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().
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

Fool Running

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.
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

elias4444

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.
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com