Trying to add more items than the capacity will throw IllegalArgumentException:
package com.logicbig.example.arrayblockingqueue;
import java.util.Arrays;
import java.util.concurrent.ArrayBlockingQueue;
public class ArrayBlockingQueueExample4 {
public static void main(String... args) {
ArrayBlockingQueue<Integer> q = new ArrayBlockingQueue<>(3, true,
Arrays.asList(1, 2, 3, 4));
System.out.println(q);
}
}
Output
Caused by: java.lang.IllegalArgumentException
at java.base/java.util.concurrent.ArrayBlockingQueue.<init>(ArrayBlockingQueue.java:305)
at com.logicbig.example.arrayblockingqueue.ArrayBlockingQueueExample4.main(ArrayBlockingQueueExample4.java:16)
... 6 more