В Thread4 при вызове showWarning нить останавливается, но проверка на isAlive() = true говорит, что нить жива, то есть нить выполняется.
Что не так?
//------------------------------------Нить 4----------------------------------------//
public interface Message {
void showWarning();
}
public static class Thread4 extends Thread implements Message {
@Override
public void run() {
Thread currentThread = Thread.currentThread();
while (!currentThread.isInterrupted()) {
System.out.println("Hi!");
}
}
@Override
public void showWarning() {
this.interrupt();
}
}
//--------------------------------------------------------------------------------//
public static void main(String[] args) throws InterruptedException {
Thread thread4 = new Thread4();
Message msg = (Message) thread4;
thread4.start();
Thread.sleep(2000);
msg.showWarning();
System.out.println(thread4.isAlive());
}