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 ForthThread());
threads.get(3).showWarning(); // какого фига тут ошибка?
threads.add(new Thread(new FithfThread()));
}
public static void main(String[] args) {
}
static class FirstThread implements Runnable {
public void run() {
System.out.println("Нить 1 запустилась");
while (true) {
}
}
}
static class SecondThread implements Runnable {
public void run() {
System.out.println("Нить 2 запустилась");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
System.out.println("InterruptedException");
}
}
}
static class ThirdThread implements Runnable {
public void run() {
while (true) {
try {
System.out.println("Ура");
Thread.sleep(500);
} catch (InterruptedException e) {
}
}
}
}
static class ForthThread extends Thread implements Runnable, Message {
@Override
public void run() {
while(!isInterrupted()) {
}
}
@Override
public void showWarning() {
this.interrupt();
}
}
static class FithfThread implements Runnable{
@Override
public void run() {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int sum = 0;
while (true) {
try {
String str = reader.readLine();
if (str.equals("N"))
break;
sum += Integer.parseInt(str);
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.print(sum);
}
}
}package com.javarush.task.task16.task1632;
public interface Message {
void showWarning();
}