Что не так? Вывод выводит верный. Ругается что не верный.
#1: 4
#1: 3
#1: 2
#1: 1
Нить прервана
#2: 4
#2: 3
#2: 2
#2: 1
Нить прервана
#3: 4
#3: 3
#3: 2
#3: 1
Нить прервана
#4: 4
#4: 3
#4: 2
#4: 1
Нить прервана
package com.javarush.task.task16.task1622;
/*
Последовательные выполнения нитей
*/
public class Solution {
public volatile static int COUNT = 4;
public static void main(String[] args) throws InterruptedException {
for (int i = 0; i < COUNT; i++) {
new SleepingThread().join();
//напишите тут ваш код
}
}
public static class SleepingThread extends Thread {
private static volatile int threadCount = 0;
private volatile int countDownIndex = COUNT;
public SleepingThread() {
super(String.valueOf(++threadCount));
start();
}
public void run() {
while (true) {
System.out.println(this);
if (--countDownIndex == 0) System.out.println("Нить прервана");
if (countDownIndex == 0) return;
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public String toString() {
return "#" + getName() + ": " + countDownIndex;
}
}
}