|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectparatask.queues.WorkStealingQueue<E>
paratask.queues.FifoLifoQueue<E>
E
- The type of elements held in this collectionpublic class FifoLifoQueue<E>
A mixed-schedule queue. Elements may be added using either a FIFO policy (addGlobal(Object)
),
or a LIFO policy (addLocal(Object)
).
If only addLocal(Object)
is used, then this collection will essentially behave like a WorkStealingQueue
.
If only addGlobal(Object)
is used, then this collection will essentially behave like a standard FIFO queue.
Having the ability to add both locally and globally allows for increased flexibility. For example, ParaTask uses this
queue to ensure fairness for non-recursive tasks, while also ensuring that recursive tasks are handled.
The "head of queue" in the context of a FifoLifoQueue refers to the element according to this schedule. There are three
possibilities where the "head of queue" element might come from. First, an
element is attempted to be taken from the thread's local queue. If this fails, then an element is removed from the
shared global queue. If this fails, an element is stolen from another thread's local queue.
Constructor Summary | |
---|---|
FifoLifoQueue()
Creates an empty queue with maximum capacity and chunksize of 1. |
|
FifoLifoQueue(java.util.Collection<? extends E> c,
int chunksize)
Creates a queue containing the specified collection with the specified chunksize. |
|
FifoLifoQueue(int capacity,
int chunksize)
Creates an empty queue with the specified chunksize and capacity. |
|
FifoLifoQueue(long[] threadPoolIDs)
Create an empty queue with unlimited capacity and chunksize of 1. |
Method Summary | |
---|---|
boolean |
add(E e)
Deprecated. If the calling thread already has a local queue, or the calling thread is registered as a worker thread, then this call is equivalent to addLocal(Object) . Otherwise,
the call is equivalent to addGlobal(Object) . It is therefore recommended to explicitly use
addLocal(Object) or addGlobal(Object) to ensure the correct intention is performed. |
boolean |
addGlobal(E e)
Add the specified element globally. |
boolean |
addLocal(E e)
Add the specified element locally. |
void |
clear()
Removes all of the elements from this collection (optional operation). |
boolean |
contains(java.lang.Object o)
Returns true if this queue contains the specified element. |
int |
drainTo(java.util.Collection<? super E> c,
int maxElements)
Removes at most the given number of available elements from this queue and adds them to the given collection. |
E |
element()
Retrieves, but does not remove, the head of this queue. |
boolean |
isEmpty()
Returns true if this collection contains no elements. |
E |
poll()
Retrieves and removes the head of this queue, or returns null if this queue is empty. |
boolean |
remove(java.lang.Object o)
Removes a single instance of the specified element from this queue, if it is present. |
void |
setThreadPoolIDs(long[] threadPoolIDs)
Set the set of threads that will be the worker-threads. |
int |
size()
Returns the number of elements in this collection. |
Methods inherited from class paratask.queues.WorkStealingQueue |
---|
addAll, containsAll, drainTo, iterator, offer, offer, peek, poll, put, remainingCapacity, remove, removeAll, retainAll, take, toArray, toArray |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface java.util.Collection |
---|
equals, hashCode |
Constructor Detail |
---|
public FifoLifoQueue()
public FifoLifoQueue(int capacity, int chunksize)
capacity
- chunksize
- public FifoLifoQueue(java.util.Collection<? extends E> c, int chunksize)
c
- chunksize
- public FifoLifoQueue(long[] threadPoolIDs)
threadPoolIDs
- setThreadPoolIDs(long[])
Method Detail |
---|
public void setThreadPoolIDs(long[] threadPoolIDs)
threadPoolIDs
- public boolean addLocal(E e)
e
- the element to add
true
(as specified by Collection.add(E)
)public boolean addGlobal(E e)
e
- the element to add
true
(as specified by Collection.add(E)
)public boolean add(E e)
addLocal(Object)
. Otherwise,
the call is equivalent to addGlobal(Object)
. It is therefore recommended to explicitly use
addLocal(Object)
or addGlobal(Object)
to ensure the correct intention is performed.
java.util.concurrent.BlockingQueue
offer
.
add
in interface java.util.Collection<E>
add
in interface java.util.concurrent.BlockingQueue<E>
add
in interface java.util.Queue<E>
add
in class WorkStealingQueue<E>
e
- the element to add
Collection.add(E)
)public boolean contains(java.lang.Object o)
java.util.concurrent.BlockingQueue
contains
in interface java.util.Collection<E>
contains
in interface java.util.concurrent.BlockingQueue<E>
contains
in class WorkStealingQueue<E>
o
- object to be checked for containment in this queue
public int drainTo(java.util.Collection<? super E> c, int maxElements)
java.util.concurrent.BlockingQueue
drainTo
in interface java.util.concurrent.BlockingQueue<E>
drainTo
in class WorkStealingQueue<E>
c
- the collection to transfer elements intomaxElements
- the maximum number of elements to transfer
public boolean remove(java.lang.Object o)
java.util.concurrent.BlockingQueue
remove
in interface java.util.Collection<E>
remove
in interface java.util.concurrent.BlockingQueue<E>
remove
in class WorkStealingQueue<E>
o
- element to be removed from this queue, if present
public E element()
java.util.Queue
peek
only in that it throws an exception
if this queue is empty.
element
in interface java.util.Queue<E>
element
in class WorkStealingQueue<E>
public E poll()
java.util.Queue
poll
in interface java.util.Queue<E>
poll
in class WorkStealingQueue<E>
public void clear()
java.util.Collection
clear
in interface java.util.Collection<E>
clear
in class WorkStealingQueue<E>
public boolean isEmpty()
java.util.Collection
isEmpty
in interface java.util.Collection<E>
isEmpty
in class WorkStealingQueue<E>
public int size()
java.util.Collection
size
in interface java.util.Collection<E>
size
in class WorkStealingQueue<E>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |