About
```java import java.util.Random; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
public class Main { public static void main(String[] args) { BlockingQueue<Integer> queue = new LinkedBlockingQueue<>();
Thread generatorThread = new Thread(new Generator(queue));
Thread checkerThread = new Thread(new Checker(queue));
Thread printerThread = new Thread(new Printer(queue));
generatorThread.start();
checkerThread.start();
printerThread.start();
}
}
class Generator implements Runnable { private BlockingQueue<Integer> queue; private Random random;
public Generator(BlockingQueue<Integer> queue) {
this.queue = queue;
this.random = new Random();
}
@Override
public void run() {
while (true) {
try {
int number = random.nextInt(100);
queue.put(number);
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
class Checker implements Runnable { private BlockingQueue<Integer> queue;
public Checker(BlockingQueue<Integer> queue) {
this.queue = queue;
}
@Override
public void run() {
while (true) {
try {
int number = queue.take();
if (number % 2 == 0) {
queue.put(number);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
class Printer implements Runnable { private BlockingQueue<Integer> queue;
public Printer(BlockingQueue<Integer> queue) {
this.queue = queue;
}
@Override
public void run() {
while (true) {
try {
int number = queue.take();
System.out.println("Even number: " + number);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}