Class JavaThreadPool

  • All Implemented Interfaces:
    IThreadPool

    public class JavaThreadPool
    extends java.lang.Object
    implements IThreadPool
    A thread pool based on the java.util.concurrent package.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.concurrent.ExecutorService executor
      The executor service.
      protected java.util.List<IChangeListener<java.lang.Void>> listeners
      The finished listeners.
      protected Future<java.lang.Void> shutdown
      Future used for performing shutdown.
    • Constructor Summary

      Constructors 
      Constructor Description
      JavaThreadPool​(boolean daemon)
      Create a new ThreadPool5.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addFinishListener​(IChangeListener<java.lang.Void> listener)
      Add a finish listener;
      void dispose()
      Shutdown the thread pool.
      void execute​(java.lang.Runnable task)
      Execute a task in its own thread.
      void executeForever​(java.lang.Runnable task)
      Execute a task in its own thread.
      boolean isRunning()
      Test if the thread pool is running.
      protected void notifyFinishListeners()
      Notify the finish listeners.
      • Methods inherited from class java.lang.Object

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

      • executor

        protected java.util.concurrent.ExecutorService executor
        The executor service.
      • listeners

        protected java.util.List<IChangeListener<java.lang.Void>> listeners
        The finished listeners.
      • shutdown

        protected Future<java.lang.Void> shutdown
        Future used for performing shutdown.
    • Constructor Detail

      • JavaThreadPool

        public JavaThreadPool​(boolean daemon)
        Create a new ThreadPool5.
    • Method Detail

      • execute

        public void execute​(java.lang.Runnable task)
        Execute a task in its own thread.
        Specified by:
        execute in interface IThreadPool
        Parameters:
        task - The task to execute.
      • executeForever

        public void executeForever​(java.lang.Runnable task)
        Execute a task in its own thread. The pool expects the thread executing the task to never return. Preferably use this method if you want to permanently retrieve a thread e.g. for repeated blocking operations.
        Specified by:
        executeForever in interface IThreadPool
        Parameters:
        task - The task to execute.
      • dispose

        public void dispose()
        Shutdown the thread pool.
        Specified by:
        dispose in interface IThreadPool
      • isRunning

        public boolean isRunning()
        Test if the thread pool is running.
        Specified by:
        isRunning in interface IThreadPool
      • notifyFinishListeners

        protected void notifyFinishListeners()
        Notify the finish listeners.