org.jclouds.concurrent
Class DynamicThreadPoolExecutor.DynamicQueue<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractQueue<E>
java.util.concurrent.LinkedBlockingQueue<E>
org.jclouds.concurrent.DynamicThreadPoolExecutor.DynamicQueue<E>
- All Implemented Interfaces:
- Serializable, Iterable<E>, Collection<E>, BlockingQueue<E>, Queue<E>
- Enclosing class:
- DynamicThreadPoolExecutor
public static class DynamicThreadPoolExecutor.DynamicQueue<E>
- extends LinkedBlockingQueue<E>
Much like a SynchronousQueue
which acts as a rendezvous channel. It
is well suited for handoff designs, in which a tasks is only queued if there
is an available thread to pick it up.
This queue is correlated with a thread-pool, and allows insertions to the
queue only if there is a free thread that can poll this task. Otherwise, the
task is rejected and the decision is left up to one of the
RejectedExecutionHandler
policies:
-
DynamicThreadPoolExecutor.ForceQueuePolicy
- forces the queue to accept the rejected task.
-
DynamicThreadPoolExecutor.TimedBlockingPolicy
- waits for a given time for the task to be
executed.
- Author:
- kimchy (Shay Banon)
- 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 |
DynamicThreadPoolExecutor.DynamicQueue
public DynamicThreadPoolExecutor.DynamicQueue()
- Creates a DynamicQueue with a capacity of
Integer.MAX_VALUE
.
DynamicThreadPoolExecutor.DynamicQueue
public DynamicThreadPoolExecutor.DynamicQueue(int capacity)
- Creates a DynamicQueue 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 © 2009-2011 jclouds. All Rights Reserved.