Class WorkingGroup<E>

All Implemented Interfaces:
Executor, ExecutorService

public class WorkingGroup<E> extends DynamicThreadPoolExecutor
This class abstracts a group of cooperating objects that together offer asynchronous message delivery to consumers. A working group is composed of 4 components: A queue of tasks, a worker-thread pool, and a consumer object. When messages (TaskWrapper Objects) are inserted into the WorkingGroup, they are inserted into the queue. The thread pool is responsible of deciding how many worker threads read the messages from the queue, and dispatch them to the consumer object. The consumer object may do anything it pleases with the messages, including forwarding them to another object(s).
  • Constructor Details

    • WorkingGroup

      public WorkingGroup(IConsumerObject<E> consumerObject, int priority, String wgName, int minPoolSize, int maxPoolSize, long keepAliveTime, int capacity, long waitTime)
      Constructs a working-group that creates new threads as needed, but will reuse previously constructed threads when they are available. If no existing thread is available, a new thread will be created and added to the pool. No more than maxPoolSize threads will be created. Threads that have not been used for a keepAliveTime timeout are terminated and removed. Thus, a pool that remains idle for long enough will not consume any resources other than the minPoolSize specified.

      Threads are created with priority and named after the working- group name wgName.

      The working-group manages a queue of tasks, which is limited in capacity. If there are no idle threads and the queue has reached it's capacity the executing thread will block for waitTime until the task can be queued. A RejectedExecutionException will be thrown at the end of the waitTime.

    • WorkingGroup

      public WorkingGroup(IConsumerObject<E> consumerObject, int priority, String wgName, int minPoolSize, int maxPoolSize, long keepAliveTime)
      Constructs a working-group that creates new threads as needed, but will reuse previously constructed threads when they are available. If no existing thread is available, a new thread will be created and added to the pool. No more than maxPoolSize threads will be created. Threads that have not been used for a keepAliveTime timeout are terminated and removed. Thus, a pool that remains idle for long enough will not consume any resources other than the minPoolSize specified.

      Threads are created with priority and named after the working- group name wgName.

      The working-group manages an unbound queue of tasks. The executing thread will never block and always favor queuing if there is no idle thread to handle the task. Equivalent to using a capacity of Integer.MAX_VALUE and a waitTime of Long.MAX_VALUE.

  • Method Details

    • start

      public void start()
      Start all core threads, causing them to idly wait for work
    • enqueueBlocked

      public void enqueueBlocked(E o)
      wraps the enqueueBlocked method of the threadpool
    • getConsumerObject

      public IConsumerObject<E> getConsumerObject()
      Returns:
      the Consumer Object of this working group.
    • shutdown

      public void shutdown()
      make a graceful "shutdown" to all the worker threads in the thread pool Initiates an orderly shutdown in which only executing tasks will complete, previously submitted tasks are ignored,and no new tasks will be accepted. Invocation has no additional effect if already shut down.
      Specified by:
      shutdown in interface ExecutorService
      Overrides:
      shutdown in class ThreadPoolExecutor
    • getWorkingGroupName

      public String getWorkingGroupName()
      Returns:
      the Working Group's name.
    • hasReachedFullCapacity

      public boolean hasReachedFullCapacity()
      Returns true if there are no more idle threads and we have reached the maximum thread-growth allowed. Otherwise, false if at least one thread can (or be spawned to) serve the incoming request.
      Returns:
      true when reached full capacity (i.e. #of active threads equals to the maximum threads allowed); false otherwise.