Проверял каждый метод отдельно - все ок, не зависает (кроме первой нити, естественно), дает необходимый результат.
При валидации виснет.
Подскажите, пожалуйста, в чем проблема.
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;
import java.util.concurrent.atomic.AtomicInteger;
public class Solution {
public static List<Thread> threads = new ArrayList<>(5);
static {
Thread1 th1 = new Thread1();
Thread2 th2 = new Thread2();
Thread3 th3 = new Thread3();
Thread4 th4 = new Thread4();
Thread5 th5 = new Thread5();
threads.add(th1);
threads.add(th2);
threads.add(th3);
threads.add(th4);
threads.add(th5);
}
public static void main(String[] args) {
}
public static class Thread1 extends Thread {
public void run() {
while (true) {}
}
}
public static class Thread2 extends Thread {
@Override
public void run() {
try
{
throw new InterruptedException();
} catch (InterruptedException m)
{
System.out.println("InterruptedException");
}
}
}
public static class Thread3 extends Thread
{
public void run() {
while (true) {
try {
System.out.println("Ура");
Thread.sleep(500);
} catch (InterruptedException m)
{
break;
}
}
}
}
public static class Thread4 extends Thread implements Message
{
public void run() {
if (Thread.currentThread().isAlive())
showWarning();
}
public void showWarning() {
Thread.currentThread().interrupt();
}
}
public static class Thread5 extends Thread {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
Integer sum = 0;
public void run()
{
while (true) {
try {
String in = reader.readLine();
if(in.equals("N")) {break;}
sum = sum + Integer.parseInt(in);
} catch (Exception m) {
}
}
System.out.println(sum);
}
}
}