feat: complete concurrency homework assignment

This commit is contained in:
user
2026-09-01 17:18:14 +04:00
parent c0bfc346fe
commit cda58045bc
10 changed files with 229 additions and 0 deletions
@@ -0,0 +1,36 @@
package com.example;
import com.example.util.ThreadUtils;
public class LiveLock {
private static boolean thread1WantsToPass = true;
private static boolean thread2WantsToPass = true;
public static void main(String[] args) {
Thread thread1 =
new Thread(
() -> {
while (thread1WantsToPass) {
System.out.println("Поток 1: Я уступаю дорогу Потоку 2...");
ThreadUtils.sleep(100);
}
System.out.println("Поток 1 прошел!");
});
Thread thread2 =
new Thread(
() -> {
while (thread2WantsToPass) {
System.out.println("Поток 2: Я уступаю дорогу Потоку 1...");
ThreadUtils.sleep(100);
}
System.out.println("Поток 2 прошел!");
});
thread1.start();
thread2.start();
}
}