Package overit.geocall.util
Class LinkedBlockingQueue<T>
java.lang.Object
overit.geocall.util.LinkedBlockingQueue<T>
This queue orders elements FIFO (first-in-first-out). The head of the queue is that element that has been on the
queue the longest time.
The tail of the queue is that element that has been on the queue the shortest time. New elements are inserted at
the tail of the queue, and the queue retrieval operations obtain elements at the head of the queue.
This queue can contains only a limited number of entry (specified by the
setCapacity(int) method);
the extra ones must wait the removal of at least one entry.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Atomically removes all of the elements from this queue.booleanReturns true if this queue contains the specified element.booleanInserts 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 false if this queue is full.poll()Retrieves and removes the head of this queue, or returns null if this queue is empty.poll(long timeout) Retrieves and removes the head of this queue, waiting if necessary until an element becomes available.voidInserts the specified element at the tail of this queue, waiting if necessary for space to become available.intReturns the number of additional elements that this queue can ideally (in the absence of memory or resource constraints) accept without blocking.voidsetCapacity(int capacity) Set the maximum number of entry that the queue can holds.intsize()Returns the number of elements in this queue.take()Retrieves and removes the head of this queue, waiting if necessary until an element becomes available.
-
Constructor Details
-
LinkedBlockingQueue
public LinkedBlockingQueue()
-
-
Method Details
-
setCapacity
public void setCapacity(int capacity) Set the maximum number of entry that the queue can holds. This value can be dynamically changed at runtime- Parameters:
capacity- the maximum number of entry that the queue can holds
-
offer
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 false if this queue is full.- Parameters:
e- the element to add- Returns:
trueif the element was added to this queue, elsefalse- Throws:
NullPointerException- if the specified element is null
-
put
Inserts the specified element at the tail of this queue, waiting if necessary for space to become available.- Parameters:
e- the element to add- Throws:
InterruptedException- if interrupted while waitingNullPointerException- if the specified element is null
-
poll
Retrieves and removes the head of this queue, or returns null if this queue is empty.- Returns:
- he head of this queue, or null if this queue is empty
-
poll
Retrieves and removes the head of this queue, waiting if necessary until an element becomes available.- Parameters:
timeout- the maximum time to wait in milliseconds.- Returns:
- the head of this queue or null if the timeout has passed and the queue is still empty
-
take
Retrieves and removes the head of this queue, waiting if necessary until an element becomes available.- Returns:
- the head of this queue
- Throws:
InterruptedException- if interrupted while waiting
-
clear
public void clear()Atomically removes all of the elements from this queue. The queue will be empty after this call returns. -
contains
Returns true if this queue contains the specified element. More formally, returns true if and only if this queue contains at least one element e such that o.equals(e).- Parameters:
o- object to be checked for containment in this queue- Returns:
trueif this queue contains the specified element
-
size
public int size()Returns the number of elements in this queue.- Returns:
- the number of elements in this queue
-
remainingCapacity
public int remainingCapacity()Returns the number of additional elements that this queue can ideally (in the absence of memory or resource constraints) accept without blocking. This is always equal to the initial capacity of this queue less the current size of this queue. Note that you cannot always tell if an attempt to insert an element will succeed by inspecting remainingCapacity because it may be the case that another thread is about to insert or remove an element.- Returns:
- the remaining capacity
-