I don't know how a thread can implement a random interface. I can't do it with an X class obj. Any help will be appreciete, tk you!
package com.codegym.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 extends Thread{
public static List<Thread> threads = new ArrayList<>(5);
static {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Thread thread1 = new Thread("1"){
@Override
public void run() {
while(true){
}
}
};
Thread thread2 = new Thread("2"){
@Override
public void run() {
try{
throw new InterruptedException();
}catch (InterruptedException e){
System.out.println("InterruptedException");
}
}
};
Thread thread3 = new Thread("3"){
@Override
public void run() {
while (true) {
try {
System.out.println("Hurray");
Thread.sleep(500);
} catch (InterruptedException e) {
}
}
}
};
Thread thread4 = new Thread("4"){
@Override
public void run() {
// ??? I have no idea !!! how to acces showWarning()
}
};
Thread thread5 = new Thread("5"){
@Override
public void run() {
int sum = 0;
while (true){
try {
String s = br.readLine();
if(!s.equals("N")) {
int a = Integer.parseInt(s);
sum += a;
} else {
System.out.println(sum);
}
} catch (IOException e) {
}
}
}
};
threads.add(thread1);
threads.add(thread2);
threads.add(thread3);
threads.add(thread4);
threads.add(thread5);
}
public static void main(String[] args) throws InterruptedException {
}
public static class X extends Thread implements Message{ // I think i need a static class to implement Message(!?) but...
@Override
public void showWarning() {
Thread.currentThread().interrupt();
}
}
}