Question 2 java answers alternative
Question 2 java answers alternative
@Override
public void run() {
while (true) {
buffer.read();
try {
Thread.sleep((int) (Math.random() * 1000));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
System.out.println("ReaderTask interrupted.");
break;
}
}
}
}
}
Key Features:
1. Thread Safety:
2. Thread Pool:
o ExecutorService manages the threads, ensuring efficient
execution.
3. Graceful Handling: