Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4108570
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:40:32+00:00 2026-05-20T21:40:32+00:00

Here is a quote from a textbook I’m reading at the moment: That is,

  • 0

Here is a quote from a textbook I’m reading at the moment:

“That is, whenever a thread needs to
execute a loop with a lot of
iterations, it is good practice to put
a sleep() in each iteration
– Event short sleep times, such as 5 milliseconds, can reduce the overall
CPU usage of the application from
100% to > 1%”

It’s a good practice, I believe, but; doesn’t scheduler does exactly that – A bit of time to thread1; suspend thread1; A bit of time to thread2…etc. I can’t grasp such drop rate, anyone willing to enlighten me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T21:40:33+00:00Added an answer on May 20, 2026 at 9:40 pm

    You see this a lot in programs that update the display of something. It’s called Busy Waiting, and that’s bad.

    If you have a loop that does something like this

    public void run() {
        while(running) {
            gui.render();
        }
    }
    

    You’re going to chew up your CPU when you really don’t need to. Do you need to render it, over and over and over, 100000+ times a second? No, you really only need about 30 frames a second.

    public void run() {
        while(running) {
            gui.render();
            try { Thread.sleep(10); } catch(InterruptedException e) { /* we tried */}
        }
    }
    

    This will limit you to a little under 100 frames per second, and you’ll end up with a much better performance.

    You don’t always want this for processor intensive background threads, as you want them to have priority. That being said, if your background takes all the CPU, how will you process further input (like, I don’t know, a CANCEL button because you didn’t mean to start that intensive, hours-long calculation?)

    So adding a small sleep to your threads CAN BE a very good decision.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's a quote from Android's Dev Guide: A central feature of Android is that
Here's the line from App.Config: <add key=CheckFileFormatString value=P{0}\t&quot;{1}, {2}&quot;\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}/> Here's the code that puts
Here is a quote from https://stackoverflow.com/users/893/greg-hewgill answer to Explain Python's slice notation . Python
for more info of what I mean here is a quote from the user
So here is the situation-- a quote from my boss: [...] we need to
I'm trying to set up Jekyll so that a quote from the first post
From here , I am trying to get data from stock quote for every
Here is a quote from the book Introduction to Assembly language about RISC (vs
Check out this quote from here , towards the bottom of the page. (I
Simple question here. Quote from the PostgreSQL Getting Started guide: PostgreSQL can be installed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.