Java.util.concurrent Queues: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
(15 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
=Internal= | =Internal= | ||
* [[java.util.concurrent# | * [[java.util.concurrent#Queues|java.util.concurrent]] | ||
=Overview= | =Overview= | ||
Line 7: | Line 7: | ||
=Blocking Queue= | =Blocking Queue= | ||
External | {{External|https://docs.oracle.com/javase/10/docs/api/java/util/concurrent/BlockingQueue.html}} | ||
<tt>java.util.concurrent.BlockingQueue<E></tt> is a <tt>java.util.Queue</tt> that | <tt>java.util.concurrent.BlockingQueue<E></tt> is a <tt>java.util.Queue</tt> that has operations that wait for the queue to become non-empty when retrieving an element, and wait for space to become available in the queue when storing an element. When configured with a fixed size (example <tt>[[#ArrayBlockingQueue|ArrayBlockingQueue]]</tt>), it can be used as a memory sprawl control mechanisms, providing memory-safe separation between threads. | ||
'''Insertion Operations''': | |||
* put() blocks if the queue is full. | |||
* add() throws exception if the queue is full. | |||
* offer() attempts to insert and immediately returns <tt>true</tt> if the insertion was successful or <tt>false</tt> if no space is available. offer() has an overloaded version that times out. | |||
'''Removal Operations''': | |||
* take() blocks if the queue is empty. | |||
* remove() throws exception if the queue is empty. | |||
* poll() attempts to remove the head of the queue and returns null if the queue is empty. poll() has an overloaded version that times out. | |||
'''Inspection Operations''': | |||
* peek() retrieves, but does not remove, the head of this queue, or returns null if this queue is empty. | |||
* element() retrieves, but does not remove, the head of this queue, and throws exception if the queue is empty. | |||
<tt>java.util.concurrent.BlockingQueue<E></tt> has the following implementations: | |||
==ArrayBlockingQueue== | |||
==LinkedBlockingQueue== |
Latest revision as of 17:29, 23 March 2018
Internal
Overview
Blocking Queue
java.util.concurrent.BlockingQueue<E> is a java.util.Queue that has operations that wait for the queue to become non-empty when retrieving an element, and wait for space to become available in the queue when storing an element. When configured with a fixed size (example ArrayBlockingQueue), it can be used as a memory sprawl control mechanisms, providing memory-safe separation between threads.
Insertion Operations:
- put() blocks if the queue is full.
- add() throws exception if the queue is full.
- offer() attempts to insert and immediately returns true if the insertion was successful or false if no space is available. offer() has an overloaded version that times out.
Removal Operations:
- take() blocks if the queue is empty.
- remove() throws exception if the queue is empty.
- poll() attempts to remove the head of the queue and returns null if the queue is empty. poll() has an overloaded version that times out.
Inspection Operations:
- peek() retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.
- element() retrieves, but does not remove, the head of this queue, and throws exception if the queue is empty.
java.util.concurrent.BlockingQueue<E> has the following implementations: