Blocking Queue Demo
Blocking Queue Demo
collectionframework;
import java.util.Comparator;
import java.util.concurrent.*;
this.queue = queue;
@Override
while (true) {
try {
queue.put(value++);
Thread.sleep(1000);
} catch (Exception e) {
Thread.currentThread().interrupt();
System.out.println("Producer interrupted");
}
}
this.queue = queue;
@Override
while (true) {
try {
Thread.sleep(2000);
} catch (Exception e) {
Thread.currentThread().interrupt();
System.out.println("Consumer interrupted");
producer.start();
consumer.start();
queue2.add("apple");
queue2.add("banana");
queue2.add("cherry");
System.out.println(queue2);