Package org.vrspace.server.core
Class PausableThreadPoolExecutor
java.lang.Object
java.util.concurrent.AbstractExecutorService
java.util.concurrent.ThreadPoolExecutor
org.vrspace.server.core.PausableThreadPoolExecutor
- All Implemented Interfaces:
Executor,ExecutorService
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)
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.concurrent.ThreadPoolExecutor
ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicy -
Constructor Summary
ConstructorsConstructorDescriptionPausableThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbeforeExecute(Thread thread, Runnable runnable) booleanisPaused()booleanstatic PausableThreadPoolExecutorvoidpause()Pause the executionvoidresume()Resume pool executionMethods inherited from class java.util.concurrent.ThreadPoolExecutor
afterExecute, allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, execute, finalize, getActiveCount, getCompletedTaskCount, getCorePoolSize, getKeepAliveTime, getLargestPoolSize, getMaximumPoolSize, getPoolSize, getQueue, getRejectedExecutionHandler, getTaskCount, getThreadFactory, isShutdown, isTerminated, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setCorePoolSize, setKeepAliveTime, setMaximumPoolSize, setRejectedExecutionHandler, setThreadFactory, shutdown, shutdownNow, terminated, toStringMethods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submit
-
Constructor Details
-
PausableThreadPoolExecutor
public PausableThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue) - Parameters:
corePoolSize- The size of the poolmaximumPoolSize- The maximum size of the poolkeepAliveTime- The amount of time you wish to keep a single task aliveunit- The unit of time that the keep alive time representsworkQueue- The queue that holds your tasks
-
-
Method Details
-
newSingleThreadExecutor
-
beforeExecute
- Overrides:
beforeExecutein classThreadPoolExecutor- Parameters:
thread- The thread being executedrunnable- 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
-