Рекомендация от ментора:
Нить 4 из списка threads должна реализовать интерфейс Message.
Что? Где я туплю?
package com.javarush.task.task16.task1632;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class Solution {
public static List<Thread> threads = new ArrayList<>(5);
static {
threads.add(new Thread(new firstThread()));
threads.add(new Thread(new secondThread()));
threads.add(new Thread(new thirdThread()));
threads.add(new Thread(new fourthThread()));
threads.add(new Thread(new fifthThread()));
}
public static void main(String[] args) {
}
public static class firstThread extends Thread {
@Override
public void run() {
while(true) {
//бесконечное исполнение
}
}
}
public static class secondThread extends Thread {
@Override
public void run() {
try {
while (true) {
Thread.sleep(1);
}
} catch (InterruptedException e) {
System.out.println("InterruptedException");
}
}
}
public static class thirdThread extends Thread {
@Override
public void run() {
try {
while (true) {
System.out.println("Ура");
Thread.sleep(500);
}
} catch (InterruptedException e) {
}
}
}
public static class fourthThread extends Thread implements Message {
@Override
public void run() {
while(!this.isInterrupted()) {
}
}
public void showWarning() {
this.interrupt();
}
}
public static class fifthThread extends Thread {
@Override
public void run() {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int sum = 0;
String line = "";
while (!(line = reader.readLine()).equals("N")) {
sum += Integer.parseInt(line);
}
reader.close();
System.out.println(sum);
} catch (IOException e) {
}
}
}
}