Уже как только не пытался. 4 нитка не проходит валидацию.
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 Thread1()));
threads.add(new Thread(new Thread2()));
threads.add(new Thread(new Thread3()));
threads.add(new Thread(new Thread4()));
threads.add(new Thread(new Thread5()));
}
public static void main(String[] args) {
for(Thread thread : threads){
thread.start();
}
}
public static class Thread1 implements Runnable {
@Override
public void run() {
while (true) {
}
}
}
public static class Thread2 implements Runnable {
@Override
public void run() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
System.out.println("InterruptedException");
}
}
}
public static class Thread3 implements Runnable {
@Override
public void run() {
try {
while (true) {
System.out.println("Ура");
Thread.sleep(500);
}
}catch(InterruptedException e){
e.printStackTrace();
}
}
}
public static class Thread4 implements Runnable, Message {
private boolean myStop = false;
@Override
public void showWarning() {
myStop = true;
}
@Override
public void run() {
try {
while ( !myStop ) {
Thread.sleep(0);
}
} catch (InterruptedException e) {}
}
}
public static class Thread5 implements Runnable {
ArrayList<Integer> list = new ArrayList<>();
@Override
public void run() {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
while (true) {
String string = null;
try {
string = bufferedReader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (!string.equals("N")) {
list.add(Integer.parseInt(string));
} else {
break;
}
}
int sum = 0;
for (Integer integer : list) {
sum += integer;
}
System.out.println(sum);
}
}
}