Package org.jbrew.concurrent
Class BoundedTaskQueue
java.lang.Object
org.jbrew.concurrent.AbstractBlockingTaskQueue
org.jbrew.concurrent.BoundedTaskQueue
public class BoundedTaskQueue extends AbstractBlockingTaskQueue
A
BoundedTaskQueue
is an unordered, bounded implementation of a TaskQueue
.
This implementation is ThreadSafe
, as it can safely handle multiple consumer
and producer threads writing and/or reading from it.- Author:
- nealk
-
Field Summary
-
Constructor Summary
Constructors Constructor Description BoundedTaskQueue(int capacity)
-
Method Summary
Modifier and Type Method Description void
enqueue(Task<? extends java.lang.Object> task)
Adds an element to the head of the queue.int
getCapacity()
-
Constructor Details
-
BoundedTaskQueue
public BoundedTaskQueue(int capacity)
-
-
Method Details
-
enqueue
Description copied from interface:TaskQueue
Adds an element to the head of the queue. When the queue is full (bounded implementations only), the callingThread
is blocked until capacity in the queue has been released.- Parameters:
task
- - TheTask
which is being added to the queue.- Throws:
java.lang.InterruptedException
- - The method hands off the responsibility of exception handling to the caller in event of an interruption in theThread
.
-
getCapacity
public int getCapacity()- Returns:
- the capacity of this
AbstractBlockingTaskQueue
.
-