Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

mc3712

[java] Thread performance question

This topic is 5991 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

Here''s an example run method: public void run() { while(true) { repaint(); } } This method eats 90% of my processor usage. And this.. public void run() { while(true) { repaint(); try { Thread.sleep(1); } catch (InterruptedException ioe) { } } } .. only about 5%. Why?

Share this post


Link to post
Share on other sites
Advertisement
The first loop is busy all the time while the second loop apparently sleeps a lot of the time. Calling repaint takes a lot less than a millisecond as all it does is to create a repaint event and add it to the event queue (it does not actually repaint anything). You can also not be sure that the Thread.sleep call uses a millisecond-precision timer, it might sleep longer.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!