Class PausableThreadPoolExecutor

All Implemented Interfaces:
Executor, ExecutorService

public class PausableThreadPoolExecutor extends ThreadPoolExecutor
A light wrapper around the ThreadPoolExecutor. It allows for you to pause execution and resume execution when ready. It is very handy for games that need to pause.
Author:
Matthew A. Johnston (warmwaffles)
  • Constructor Details

    • PausableThreadPoolExecutor

      public PausableThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue)
      Parameters:
      corePoolSize - The size of the pool
      maximumPoolSize - The maximum size of the pool
      keepAliveTime - The amount of time you wish to keep a single task alive
      unit - The unit of time that the keep alive time represents
      workQueue - The queue that holds your tasks
  • Method Details

    • newSingleThreadExecutor

      public static PausableThreadPoolExecutor newSingleThreadExecutor()
    • beforeExecute

      protected void beforeExecute(Thread thread, Runnable runnable)
      Overrides:
      beforeExecute in class ThreadPoolExecutor
      Parameters:
      thread - The thread being executed
      runnable - The runnable task
    • isRunning

      public boolean isRunning()
    • isPaused

      public boolean isPaused()
    • pause

      public void pause()
      Pause the execution
    • resume

      public void resume()
      Resume pool execution