CodeGym gives me this warning but in IDEA everything worked just fine. The program quits itself as soon as "Double Check" shows up.
Also please remove the "Thread.stop()", that's not part of my code.
Thanks!
package com.codegym.task.task16.task1611;
/*
Clocks
*/
public class Solution {
public static volatile boolean isStopped = false;
public static void main(String[] args) throws InterruptedException {
Clock clock = new Clock();
Thread.sleep(2000);
isStopped = true;
System.out.println("the clock has to be stopped");
Thread.sleep(2000);
System.out.println("Double-check");
Thread.stop();
}
public static class Clock extends Thread {
public Clock() {
setPriority(MAX_PRIORITY);
start();
}
public void run() {
try {
while (!isStopped) {
printTickTock();
}
} catch (InterruptedException e) {
}
}
private void printTickTock() throws InterruptedException {
while (!isStopped) {
System.out.println("Tick");
Thread.sleep(500);
System.out.println("Tock");
Thread.sleep(500);
}
//write your code here
}
}
}