Время изменяется на 1 секунду. Становится "В г. Лондон сейчас 23:59:58!".
Обратно в цикле в printTime() не заходит, зависает на "В г. Лондон сейчас 23:59:58!".
Почему?
package com.javarush.task.task16.task1613;
/*
Big Ben clock
*/
import java.sql.Time;
import java.time.LocalTime;
import java.util.Date;
public class Solution {
public static volatile boolean isStopped = false;
public static void main(String[] args) throws InterruptedException {
Clock clock = new Clock("Лондон", 23, 59, 57);
Thread.sleep(4000);
isStopped = true;
Thread.sleep(1000);
}
public static class Clock extends Thread {
private String cityName;
private int hours;
private int minutes;
private int seconds;
public Clock(String cityName, int hours, int minutes, int seconds) {
this.cityName = cityName;
this.hours = hours;
this.minutes = minutes;
this.seconds = seconds;
start();
}
public void run() {
try {
while (!isStopped) {
printTime();
}
} catch (InterruptedException e) {
}
}
private void printTime() throws InterruptedException {
//add your code here - добавь код тут
if (hours == 0 && minutes == 0 && seconds == 0) {
System.out.println(String.format("В г. %s сейчас полночь!", cityName));
} else {
LocalTime current1 = LocalTime.of(hours,minutes,seconds);
Thread.sleep(1000);
LocalTime current2 = current1.plusSeconds(1);
System.out.println(String.format("В г. %s сейчас %d:%d:%d!", cityName,
current2.getHour(), current2.getMinute(), current2.getSecond()));
}
}
}
}