org.jclouds.concurrent
Class DynamicThreadPoolExecutor.DynamicQueue<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractQueue<E>
          extended by java.util.concurrent.LinkedBlockingQueue<E>
              extended by 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:

  1. DynamicThreadPoolExecutor.ForceQueuePolicy - forces the queue to accept the rejected task.
  2. DynamicThreadPoolExecutor.TimedBlockingPolicy - waits for a given time for the task to be executed.

Author:
kimchy (Shay Banon)
See Also:
Serialized Form

Constructor Summary
DynamicThreadPoolExecutor.DynamicQueue()
          Creates a DynamicQueue with a capacity of Integer.MAX_VALUE.
DynamicThreadPoolExecutor.DynamicQueue(int capacity)
          Creates a DynamicQueue with the given (fixed) capacity.
 
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
 
Methods inherited from class java.util.AbstractQueue
add, addAll, element, remove
 
Methods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, removeAll, retainAll
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.concurrent.BlockingQueue
add, contains
 
Methods inherited from interface java.util.Queue
element, remove
 
Methods inherited from interface java.util.Collection
addAll, containsAll, equals, hashCode, isEmpty, removeAll, retainAll
 

Constructor Detail

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.
Method Detail

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-2012 jclouds. All Rights Reserved.