Есть ли разница между this.interrupt(); и Thread.currentThread().interrupt() ? Валидатор 1й вариант пропускает второй не пропускает
(метод showWarning() будет вызываться ТОЛЬКО у объекта Tr_4 )
static class Tr_4 extends Thread implements Message{
public void showWarning(){
this.interrupt(); //Thread.currentThread().interrupt() - такую конструкцию валидатор авторского решения не пропускает
}
public void run(){
while(!Thread.currentThread().isInterrupted()){
}
}
}
---------------------------------------------
Полный Код
public class Solution {
public static List<Thread> threads = new ArrayList<>(5);
static {
threads.add(new Tr_1());
threads.add(new Tr_2());
threads.add(new Tr_3());
threads.add(new Tr_4());
threads.add(new Tr_5());
}
public static void main(String[] args) throws InterruptedException{
}
static class Tr_1 extends Thread{
public void run(){ while(true){} }
}
static class Tr_2 extends Thread{
public void run(){
try{
Thread.sleep(1000);
}catch (InterruptedException e){ System.out.println("InterruptedException"); }
}
}
static class Tr_3 extends Thread {
public void run() {
while (true) {
System.out.println("Ура");
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
}
}
}
static class Tr_4 extends Thread implements Message{
public void showWarning(){
this.interrupt();
}
public void run(){
while(!Thread.currentThread().isInterrupted()){
}
}
}
static class Tr_5 extends Thread{
@Override
public void run(){
Scanner sc = new Scanner(System.in);
int s = 0;
String str;
while (!(str = sc.nextLine()).equals("N")){
s+=Integer.parseInt(str);
}
System.out.println(s);
}
}
}