Class ConcurrentExecutor

  • All Implemented Interfaces:
    java.util.concurrent.Executor

    public class ConcurrentExecutor
    extends java.lang.Object
    implements java.util.concurrent.Executor
    The ConcurrentExecutor object is used to execute tasks in a thread pool. This creates a thread pool with an unbounded list of outstanding tasks, which ensures that any system requesting a task to be executed will not block when handing it over.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private ExecutorQueue queue
      This is the queue used to enqueue the tasks for execution.
    • Constructor Summary

      Constructors 
      Constructor Description
      ConcurrentExecutor​(java.lang.Class type)
      Constructor for the ConcurrentExecutor object.
      ConcurrentExecutor​(java.lang.Class type, int size)
      Constructor for the ConcurrentExecutor object.
      ConcurrentExecutor​(java.lang.Class type, int rest, int active)
      Constructor for the ConcurrentExecutor object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void execute​(java.lang.Runnable task)
      The execute method is used to queue the task for execution.
      void stop()
      This is used to stop the executor by interrupting all running tasks and shutting down the threads within the pool.
      void stop​(long wait)
      This is used to stop the executor by interrupting all running tasks and shutting down the threads within the pool.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • queue

        private final ExecutorQueue queue
        This is the queue used to enqueue the tasks for execution.
    • Constructor Detail

      • ConcurrentExecutor

        public ConcurrentExecutor​(java.lang.Class type)
        Constructor for the ConcurrentExecutor object. This is used to create a pool of threads that can be used to execute arbitrary Runnable tasks. If the threads are busy this will simply enqueue the tasks and return.
        Parameters:
        type - this is the type of runnable that this accepts
      • ConcurrentExecutor

        public ConcurrentExecutor​(java.lang.Class type,
                                  int size)
        Constructor for the ConcurrentExecutor object. This is used to create a pool of threads that can be used to execute arbitrary Runnable tasks. If the threads are busy this will simply enqueue the tasks and return.
        Parameters:
        type - this is the type of runnable that this accepts
        size - this is the number of threads to use in the pool
      • ConcurrentExecutor

        public ConcurrentExecutor​(java.lang.Class type,
                                  int rest,
                                  int active)
        Constructor for the ConcurrentExecutor object. This is used to create a pool of threads that can be used to execute arbitrary Runnable tasks. If the threads are busy this will simply enqueue the tasks and return.
        Parameters:
        type - this is the type of runnable that this accepts
        rest - this is the number of threads to use in the pool
        active - this is the maximum size the pool can grow to
    • Method Detail

      • execute

        public void execute​(java.lang.Runnable task)
        The execute method is used to queue the task for execution. If all threads are busy the provided task is queued and waits until all current and outstanding tasks are finished.
        Specified by:
        execute in interface java.util.concurrent.Executor
        Parameters:
        task - this is the task to be queued for execution
      • stop

        public void stop()
        This is used to stop the executor by interrupting all running tasks and shutting down the threads within the pool. This will return once it has been stopped, and no further tasks will be accepted by this pool for execution.
      • stop

        public void stop​(long wait)
        This is used to stop the executor by interrupting all running tasks and shutting down the threads within the pool. This will return once it has been stopped, and no further tasks will be accepted by this pool for execution.
        Parameters:
        wait - the number of milliseconds to wait for it to stop