public class BlockingQueueDemo1 {
public static void main(String[] args) throws InterruptedException {
ArrayBlockingQueue arrayBlockingQueue1 = new ArrayBlockingQueue<Integer>(1);
ArrayBlockingQueue arrayBlockingQueue2 = new ArrayBlockingQueue<Integer>(1);
new Thread(()->{
try {
while (true){
System.out.print(arrayBlockingQueue1.take());
arrayBlockingQueue2.put(2);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}).start();
new Thread(()->{
try {
while (true){
arrayBlockingQueue1.put(1);
System.out.print(arrayBlockingQueue2.take());
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}).start();
}
}