• Advertisement

Archived

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

[java] Thread performance question

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