Class AutoCloseableExecutorService
java.lang.Object
java.util.concurrent.AbstractExecutorService
java.util.concurrent.ThreadPoolExecutor
nonapi.io.github.classgraph.concurrency.AutoCloseableExecutorService
- All Implemented Interfaces:
AutoCloseable
,Executor
,ExecutorService
A ThreadPoolExecutor that can be used in a try-with-resources block.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.concurrent.ThreadPoolExecutor
ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicy
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAutoCloseableExecutorService
(int numThreads) A ThreadPoolExecutor that can be used in a try-with-resources block. -
Method Summary
Modifier and TypeMethodDescriptionvoid
afterExecute
(Runnable runnable, Throwable throwable) Catch exceptions from both submit() and execute(), and callInterruptionChecker.interrupt()
to interrupt all threads.void
close()
Shut down thread pool on close().Methods inherited from class java.util.concurrent.ThreadPoolExecutor
allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, beforeExecute, 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, toString
Methods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submit
-
Field Details
-
interruptionChecker
TheInterruptionChecker
.
-
-
Constructor Details
-
AutoCloseableExecutorService
public AutoCloseableExecutorService(int numThreads) A ThreadPoolExecutor that can be used in a try-with-resources block.- Parameters:
numThreads
- The number of threads to allocate.
-
-
Method Details
-
afterExecute
Catch exceptions from both submit() and execute(), and callInterruptionChecker.interrupt()
to interrupt all threads.- Overrides:
afterExecute
in classThreadPoolExecutor
- Parameters:
runnable
- the Runnablethrowable
- the Throwable
-
close
public void close()Shut down thread pool on close().- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceExecutorService
-