I tried interrupting threads in the code and it does print Thread Interrupted but the code wont verify.
package com.codegym.task.task16.task1622;
/*
Consecutive threads
*/
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();
//write your code here
}
}
public static class SleepingThread extends Thread {
private static volatile int threadCount = 0;
private volatile int countdownIndex = COUNT;
public SleepingThread() throws InterruptedException {
super(String.valueOf(++threadCount));
start();
//join();
}
public void run() {
if (Thread.currentThread().isInterrupted()){
System.out.println("Thread Interrupted");
return ;
}
while (true) {
System.out.println(this);
if (--countdownIndex == 0) return;
//write your code here
try {
Thread.sleep(10);
} catch (InterruptedException e) {
System.out.println("Thread Interrupted");
//e.printStackTrace();
}
}
}
public String toString() {
return "#" + getName() + ": " + countdownIndex;
}
}
}