Ребяты, уже так извращаюсь...просто нет слов...вытягиваю ссылку на запущенный поток из ThreadGroup...вопрос не в том почему не получается, а почему валидатор матерится 🤪🤪🤪
package com.javarush.task.task16.task1619;
/*
А без interrupt слабо?
*/
public class Solution {
public static void main(String[] args) throws InterruptedException {
Runnable runnable = new TestThread();
Thread t = new Thread(runnable);
t.start();
Thread.sleep(3000);
ourInterruptMethod();
}
public static void ourInterruptMethod() {
Thread[] list = new Thread[Thread.currentThread().getThreadGroup().activeCount()];
Thread.currentThread().getThreadGroup().enumerate(list);
list[list.length - 1].setName("interrupted");
}
public static class TestThread implements Runnable {
public void run() {
while (!"interrupted".equals(Thread.currentThread().getName())) {
try {
System.out.println("he-he");
Thread.sleep(500);
} catch (InterruptedException e) {
}
}
}
}
}