Inserts the specified element at the tail of this queue if it is possible to do so immediately without exceeding the
queue's capacity, returning
true
upon success and throwing an
IllegalStateException
if this queue is full.
package com.logicbig.example.arrayblockingqueue;
import java.util.concurrent.ArrayBlockingQueue;
public class AddExample2 {
public static void main(String... args) {
ArrayBlockingQueue<Integer> q = new ArrayBlockingQueue<>(1);
q.add(1);
q.add(2);
}
}
Output
Caused by: java.lang.IllegalStateException: Queue full
at java.base/java.util.AbstractQueue.add(AbstractQueue.java:98)
at java.base/java.util.concurrent.ArrayBlockingQueue.add(ArrayBlockingQueue.java:326)
at com.logicbig.example.arrayblockingqueue.AddExample2.main(AddExample2.java:15)
... 6 more