Программа ни чего не выводит на экран. В отладчике вижу, что на первом же входе срабатывает проверка
if (!current.isInterrupted())
return;
Показывается что условие всегда исполняется и в итоге работа нормальная прерывается.
package com.javarush.task.task16.task1617;
/*
Отсчет на гонках
*/
public class Solution {
public static volatile int numSeconds = 3;
public static void main(String[] args) throws InterruptedException {
RacingClock clock = new RacingClock();
//add your code here - добавь код тут
Thread.sleep(3500);
clock.interrupt();
}
public static class RacingClock extends Thread {
public RacingClock() {
start();
}
public void run() {
//add your code here - добавь код тут
Thread current = Thread.currentThread();
if (!current.isInterrupted())
return;
while (true) {
if (!current.isInterrupted()) {
System.out.print("Прервано!");
break;
}
if ( numSeconds > 0 )
System.out.print(numSeconds + " ");
else {
System.out.print("Марш!");
break;
}
numSeconds--;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}