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();
}
}
});