ArrayBlockingQueue
ArrayBlockingQueue introduction
The ArrayBlockingQueue class implements the BlockingQueue interface.
ArrayBlockingQueue is capacity limited, its internal use an array of elements, which means it cannot store an unlimited number of elements.
It has certain storage quantity limit, when initializing the object determines the number of size, then cannot be changed.
ArrayBlockingQueue is a FIFO order to preserve elements.
By default, the sort does not guarantee. However, the constructor will fairness (fairness) set to true and the structure of the queue is allowed in accordance with FIFO sequential access thread.
Fairness usually degrades the throughput, but also reduces the variability and avoid the "imbalance".
Initialization
// Parameter 1: structural capacity 1024 queue BlockingQueue queue = new ArrayBlockingQueue(1024); // Parameter 2: if true, according to FIFO sequential access insertion or by blocking a thread queue is removed; if false, the access sequence is uncertain. BlockingQueue queue = new ArrayBlockingQueue(1024,true); // Parameter 3: can be an existing set of objects as the initialization data. BlockingQueue queue = new ArrayBlockingQueue(1024,true,collection);
Matters needing attention
It is bounded blocking queue. It is composed of an array, the array size is specified in the constructor, and can not be changed.
It is thread safe queue.
Do not accept the null element.
Fairness can be specified in the constructor.
This class and its iterator is all optional methods of Collection and Iterator interface.
The size specified in the constructor. Capacity can not be automatically extended, no manual extension interface.
Posted by Victor at March 05, 2014 - 8:29 AM