Class DynamicQueue<E>

All Implemented Interfaces:
Serializable, Iterable<E>, Collection<E>, BlockingQueue<E>, Queue<E>

public class 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. ForceQueuePolicy - forces the queue to accept the rejected task.
  2. TimedBlockingPolicy - waits for a given time for the task to be executed.
Since:
6.5
Author:
moran
See Also:
  • Constructor Details

    • DynamicQueue

      public DynamicQueue()
      Creates a DynamicQueue with a capacity of Integer.MAX_VALUE.
    • DynamicQueue

      public DynamicQueue(int capacity)
      Creates a DynamicQueue with the given (fixed) capacity.
      Parameters:
      capacity - the capacity of this queue.
  • Method Details

    • 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: