Class JavaThreadPool

java.lang.Object
jadex.concurrent.JavaThreadPool
All Implemented Interfaces:
IThreadPool

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

    • executor

      protected ExecutorService executor
      The executor service.
    • listeners

      protected List<jadex.common.IChangeListener<Void>> listeners
      The finished listeners.
    • shutdown

      protected jadex.future.Future<Void> shutdown
      Future used for performing shutdown.
  • Constructor Details

    • JavaThreadPool

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

    • execute

      public void execute(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(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
    • addFinishListener

      public void addFinishListener(jadex.common.IChangeListener<Void> listener)
      Add a finish listener;
      Specified by:
      addFinishListener in interface IThreadPool
    • notifyFinishListeners

      protected void notifyFinishListeners()
      Notify the finish listeners.