Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Pausing Execution?!

Started by SirGorthon Sep 24, 2005 at 9:33 PM 4 replies 1.1k views
Original Post
SirGorthon
SirGorthon
Howdy ya'll! I have a mostly event driven program, and I was wondering if there was a handy way to pause execution other than the sleep() function in Thread! There are suspend functions and stuff in Thread but the website says those are freeze-prone! I was just wondering if there's a save round-about way to pause my program's execution other than telling it to sleep and check a boolean every few seconds! Thanks bunches guys! SirGorthon
H_o_p_s
H_o_p_s
Why don't you want to use the sleep method? It takes almost no cpu (1-2% on my 1.33GHz) to check it every 33ms...

I don't know of any other method, but let me assure you that sleeping is not a resource hog.
BRING BACK THE BLACK (or at least something darker)
SirGorthon
SirGorthon
Indeed! Thanks for the input! (I was raised on 486's and the like, so it's been engraved in my head to be as efficient as possible :()

I've also been wondering - Has Java 1.5 fixed the bit about currentTimeMillis() only updating every ~30 ms??
H_o_p_s
H_o_p_s
Java 1.5 has a function that returns ns (nanoseconds) which works (as far as I know) natively on all platforms. Theis means that with a new acurate timer, that sleep is even more acurate.

The reason in the past that it would only sleep 50ms was because in win9* the timer used by java would only allow it to go as low as 50 ms. The same piece of code running on OSX or WinXP would go all the way down to somewhere around 5ms. Anywhere below 5ms you don't really need to be sleeping though... [smile]

So to answer your question, yes. It has been fixed in 1.5, and even in 1.4.2 to certain platforms.
BRING BACK THE BLACK (or at least something darker)
SirGorthon
SirGorthon
Ah!

Thanks bunches for the help H_o_p_s!

I sure appreciate it! :D
Zahlman
Zahlman
You could always set up a few different threads and arrange for them to wait/notify each other as needed, but it's tricky to get right.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.