Class ManagedExecutor
java.lang.Object
dev.ua.theroer.magicutils.platform.ManagedExecutor
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
ManagedScheduler
A thin
AutoCloseable wrapper around an ExecutorService.
This allows thread pools to be registered with MagicRuntime.manage()
for automatic shutdown when the runtime closes.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidSubmits a task for asynchronous execution.executor()Returns the underlying executor service.booleanReturns true if the executor has been shut down.Runs a task asynchronously and returns a future.voidshutdown()Shuts down the backing executor, attempting orderly termination first.voidImmediately shuts down the backing executor.<T> CompletableFuture<T> supplyAsync(Supplier<T> supplier) Supplies a value asynchronously and returns a future.
-
Method Details
-
executor
Returns the underlying executor service.- Returns:
- backing executor
-
execute
Submits a task for asynchronous execution.- Parameters:
task- task to run
-
runAsync
Runs a task asynchronously and returns a future.- Parameters:
task- task to run- Returns:
- future for completion
-
supplyAsync
Supplies a value asynchronously and returns a future.- Type Parameters:
T- value type- Parameters:
supplier- value supplier- Returns:
- future for result
-
isShutdown
public boolean isShutdown()Returns true if the executor has been shut down.- Returns:
- true if shut down
-
shutdown
public void shutdown()Shuts down the backing executor, attempting orderly termination first. -
shutdownNow
public void shutdownNow()Immediately shuts down the backing executor. -
close
public void close()- Specified by:
closein interfaceAutoCloseable
-