ArrayBlockingQueue

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

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

  1. It is bounded blocking queue. It is composed of an array, the array size is specified in the constructor, and can not be changed.

  2. It is thread safe queue.

  3. Do not accept the null element.

  4. Fairness can be specified in the constructor.

  5. This class and its iterator is all optional methods of Collection and Iterator interface.

  6. The size specified in the constructor. Capacity can not be automatically extended, no manual extension interface.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Victor at March 05, 2014 - 8:29 AM