Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

What is Busy waiting in Multithreading?

Pragya Keshap answered on February 4, 2023 Popularity 1/10 Helpfulness 1/10

Contents


More Related Answers

  • does multithreading slow down the system

  • What is Busy waiting in Multithreading?

    0

    Busy waiting is also known as busy-looping or spinning. It is a

    multi-threading technique in which a process repeatedly checks if a

    condition is true.

    For example, a process can keep checking if any keyboard input is

    available.

    In general, busy waiting is considered as Anti-pattern that wastes

    processor time, so it should be avoided.

    Sample code for busy waiting is as follows:

    Thread thread = new Thread(new Runnable() {

    @Override

    public void run() {

    long timeToStop = System.currentTimeMillis() + 1000;

    long currentTime = System.currentTimeMillis();

    // Busy waiting

    while (timeToStop > currentTime) {

    currentTime = System.currentTimeMillis();

    }

    }

    });

    https://www.baeldung.com/cs/os-busy-waiting

    Popularity 1/10 Helpfulness 1/10 Language whatever
    Source: Grepper
    Link to this answer
    Share Copy Link
    Contributed on Feb 04 2023
    Pragya Keshap
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.