Jump to content
  • Advertisement
Sign in to follow this  
SirGorthon

[java] Pausing Execution?!

This topic is 4832 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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??

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!