import java.util.Scanner;
import java.util.concurrent.atomic.AtomicBoolean;
public class QueueMonitor {
private static final Scanner scanner = new Scanner(System.in);
private static AtomicBoolean running = true;
public static void main(String[] args) {
// Start the monitoring loop
monitorQueue();
}
private static void monitorQueue() {
while (running) {
System.out.println("Press Ctrl+C to stop.");
try {
scanner.nextInt(); // Wait for user input to prevent busy-waiting
} catch (Exception e) {
if (e instanceof java.util.hasNextException) {
// User pressed Ctrl+C
running = false;
}
}
// Simulate checking the queue (replace with actual queue polling logic)
checkQueue();
}
System.out.println("Monitoring stopped.");
}
private static void checkQueue() {
// Replace this with your actual queue checking logic.
// This is a placeholder.
System.out.println("Checking queue...");
// Simulate queue processing
try {
Thread.sleep(1000); // Simulate a 1-second check interval
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
System.out.println("Queue check complete.");
}
}
Add your comment