org.compass.core.util.concurrent
Class ScalingQueue<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractQueue<E>
java.util.concurrent.LinkedBlockingQueue<E>
org.compass.core.util.concurrent.ScalingQueue<E>
- All Implemented Interfaces:
- Serializable, Iterable<E>, Collection<E>, BlockingQueue<E>, Queue<E>
public class ScalingQueue<E>
- extends LinkedBlockingQueue<E>
A scaling queue that works with a ThreadPoolExecutor
in when offerring which takes the active count and the max threads into account.
- Author:
- kimchy
- See Also:
- Serialized Form
|
Method Summary |
boolean |
offer(E o)
Inserts the specified element at the tail of this queue if there is at
least one available thread to run the current task. |
void |
setThreadPoolExecutor(ThreadPoolExecutor executor)
Sets the executor this queue belongs to. |
| Methods inherited from class java.util.concurrent.LinkedBlockingQueue |
clear, drainTo, drainTo, iterator, offer, peek, poll, poll, put, remainingCapacity, remove, size, take, toArray, toArray, toString |
ScalingQueue
public ScalingQueue()
- Creates a TaskQueue with a capacity of
Integer.MAX_VALUE.
ScalingQueue
public ScalingQueue(int capacity)
- Creates a TaskQueue with the given (fixed) capacity.
- Parameters:
capacity - the capacity of this queue.
setThreadPoolExecutor
public void setThreadPoolExecutor(ThreadPoolExecutor executor)
- Sets the executor this queue belongs to.
offer
public boolean offer(E o)
- Inserts the specified element at the tail of this queue if there is at
least one available thread to run the current task. If all pool threads
are actively busy, it rejects the offer.
- Specified by:
offer in interface BlockingQueue<E>- Specified by:
offer in interface Queue<E>- Overrides:
offer in class LinkedBlockingQueue<E>
- Parameters:
o - the element to add.
- Returns:
- true if it was possible to add the element to this
queue, else false
- See Also:
ThreadPoolExecutor.execute(Runnable)
Copyright (c) 2004-2008 The Compass Project.