help me ls with the solution
package com.codegym.task.task16.task1620;
import java.util.ArrayList;
import java.util.List;
/*
One for all, all for one
*/
public class Solution {
public static byte countThreads = 3;
static List<Thread> threads = new ArrayList<>(countThreads);
public static void main(String[] args) throws InterruptedException {
initThreadsAndStart();
Thread.sleep(3000);
ourInterrupt();
}
public static void ourInterrupt() {
//write your code here
for(Thread thread : threads){
thread.interrupt();
}
}
private static void initThreadsAndStart() {
Water water = new Water("water");
for (int i = 0; i < countThreads; i++) {
threads.add(new Thread(water, "#" + i));
}
for (int i = 0; i < countThreads; i++) {
threads.get(i).start();
}
}
public static class Water implements Runnable {
private String commonResource;
public Water(String commonResource) {
this.commonResource = commonResource;
}
public void run() {
//fix 2 variables
boolean isCurrentThreadInterrupted = Thread.currentThread().isInterrupted();
String threadName = Thread.currentThread().getName();
try {
while (!isCurrentThreadInterrupted) {
System.out.println("Object " + commonResource + ", thread " + threadName);
Thread.sleep(1000);
}
} catch (InterruptedException e) {
}
}
}
}