Class ManagedExecutor

java.lang.Object
dev.ua.theroer.magicutils.platform.ManagedExecutor
All Implemented Interfaces:
AutoCloseable
Direct Known Subclasses:
ManagedScheduler

public class ManagedExecutor extends Object implements AutoCloseable
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 Details

    • executor

      public ExecutorService executor()
      Returns the underlying executor service.
      Returns:
      backing executor
    • execute

      public void execute(Runnable task)
      Submits a task for asynchronous execution.
      Parameters:
      task - task to run
    • runAsync

      public CompletableFuture<Void> runAsync(Runnable task)
      Runs a task asynchronously and returns a future.
      Parameters:
      task - task to run
      Returns:
      future for completion
    • supplyAsync

      public <T> CompletableFuture<T> supplyAsync(Supplier<T> supplier)
      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:
      close in interface AutoCloseable