Java Concurrency Livelock Example
What concurrency issue does the LivelockExample class illustrate?
public class LivelockExample {
public void performTask() {
while (true) {
if (tryToCompleteTask()) {
break;
}
Thread.yield();
}
}
public boolean tryToCompleteTask() {
// Simulate repeated failure to complete the task
return false;
}
}
A
Thread starvation, where low-priority threads never get executed.
B
Deadlock, where threads permanently wait for each other’s resources.
C
Race condition, where simultaneous access leads to inconsistent data.
D
Livelock, where threads continuously yield without making progress.
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE