怎么实现这句话?? threads 4 How to stop this thread when it call showWarning (); ?
package zh.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 {
public static List<Thread> threads = new ArrayList<>(5);
static {
Thread1 thread1=new Thread1();
Thread2 thread2=new Thread2();
Thread3 thread3=new Thread3();
Thread4 thread4=new Thread4();
Thread5 thread5=new Thread5();
threads.add(thread1);
threads.add(thread2);
threads.add(thread3);
threads.add(thread4);
threads.add(thread5);
}
public static void main(String[] args) {
}
public static class Thread1 extends Thread{
public void run(){
while (true){
}
}
}
public static class Thread2 extends Thread{
public void run(){
try {
Thread.sleep(1);
}catch (InterruptedException e){
System.out.println("InterruptedException");
}
}
}
public static class Thread3 extends Thread{
public void run(){
try {
while(true){
System.out.println("加油");
Thread.sleep(500);}
}catch (InterruptedException e){
}
}
}
public static class Thread4 extends Thread implements Message{
public static boolean aBoolean=false;
public void run(){
while (true){
showWarning();
if(aBoolean)
{break;
}
}
}
@Override
public void showWarning() {
aBoolean=true;
}
}
public static class Thread5 extends Thread{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
static int sum = 0;
public void run(){
try {
String s = null;
while (true){
s = reader.readLine();
if (s.equals("N"))
{
System.out.println(sum);
return;
}
sum += Integer.parseInt(s);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}