Class ExecutorWrapperService<T extends ExecutorService>

  • Type Parameters:
    T - actual type of the ExecutorService.
    All Implemented Interfaces:
    com.google.common.util.concurrent.Service

    public class ExecutorWrapperService<T extends ExecutorService>
    extends com.google.common.util.concurrent.AbstractIdleService
    Wraps an ExecutorService into a guava AbstractIdleService.

    Wrapping ExecutorServices into guava services allows orchestrating thread pool instances, especially shutting them down properly when shutting down a parent service instance.

    • Nested Class Summary

      • Nested classes/interfaces inherited from interface com.google.common.util.concurrent.Service

        com.google.common.util.concurrent.Service.Listener, com.google.common.util.concurrent.Service.State
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      T get()
      Gets the ExecutorService instance when service is running.
      protected void shutDown()  
      protected void startUp()  
      • Methods inherited from class com.google.common.util.concurrent.AbstractIdleService

        addListener, awaitRunning, awaitRunning, awaitTerminated, awaitTerminated, executor, failureCause, isRunning, serviceName, startAsync, state, stopAsync, toString
      • Methods inherited from interface com.google.common.util.concurrent.Service

        awaitRunning, awaitTerminated
    • Method Detail

      • startUp

        protected void startUp()
                        throws Exception
        Specified by:
        startUp in class com.google.common.util.concurrent.AbstractIdleService
        Throws:
        Exception
      • shutDown

        protected void shutDown()
                         throws Exception
        Specified by:
        shutDown in class com.google.common.util.concurrent.AbstractIdleService
        Throws:
        Exception
      • get

        public T get()
        Gets the ExecutorService instance when service is running.

        Only ever access this once the service has been started!

        Returns:
        wrapped ExecutorService instance.
        Throws:
        RuntimeException - when the service isn't running yet.