public void run() {
while (!isInterrupted()) {
}
}
public void showWarning() {
this.interrupt();
}
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);
public static void main(String[] args) {
}
static {
threads.add(new One());
threads.add(new Two());
Thread treeThread = new Thread(new Tree());
threads.add(treeThread);
Thread fourThread = new Thread(new Four());
threads.add(fourThread);
Thread fiveThread = new Thread(new Five());
threads.add(fiveThread);
}
public static class One extends Thread {
@Override
public void run() {
while (true) {
}
}
}
public static class Two extends Thread {
@Override
public void run() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
System.out.println("InterruptedException");
}
}
}
public static class Tree extends Thread {
@Override
public void run() {
while (true) {
System.out.println("Ура");
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
public static class Four extends Thread implements Message {
public void run() {
while (!isInterrupted()) {
}
}
public void showWarning() {
this.interrupt();
}
}
public static class Five extends Thread {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int sum = 0;
@Override
public void run() {
while (true) {
try {
String a = reader.readLine();
if (!a.equals("N")) {
sum += Integer.parseInt(a);
} else {
System.out.println(sum);
break;
}
} catch (IOException e) {
e.printStackTrace();
} catch (NumberFormatException e) {
System.out.println("Ошибка в символах!");
}
}
}
}
}