/
spirzen
/
it-code-examples
Обзор
Документация
Войти
/
spirzen
/
it-code-examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/java/java-503-23-019/main.java
19 строк
553 B
Spirzen
Code migration pack
09 июн 2026, 01:41
09 июн 2026, 01:41
cebc284
Код
Авторство
О чём код?
public class RaceConditionDemo { private static int sharedCounter = 0; public static void main(String[] args) throws InterruptedException { Thread t1 = new Thread(() -> { for (int i = 0; i < 1000; i++) sharedCounter++; }); Thread t2 = new Thread(() -> { for (int i = 0; i < 1000; i++) sharedCounter++; }); t1.start(); t2.start(); t1.join(); t2.join(); System.out.println("Ожидаемо: 2000, фактически: " + sharedCounter); } }