Class Executors


  • public final class Executors
    extends Object
    Additional factory and utility methods for executors.

    Use this instead of Executors, because it ensures that the returned Executor uses a ThreadFactory that is named, has a logging UncaughtExceptionHandler, and returns (Guava's) ListenableFuture.

    • Field Detail

      • DEFAULT_TIMEOUT_FOR_SHUTDOWN

        public static final long DEFAULT_TIMEOUT_FOR_SHUTDOWN
        See Also:
        Constant Field Values
      • DEFAULT_TIMEOUT_UNIT_FOR_SHUTDOWN

        public static final TimeUnit DEFAULT_TIMEOUT_UNIT_FOR_SHUTDOWN
    • Method Detail

      • newListeningSingleThreadExecutor

        public static com.google.common.util.concurrent.ListeningExecutorService newListeningSingleThreadExecutor​(String namePrefix,
                                                                                                                  org.slf4j.Logger logger)
        Creates a single thread executor with a ThreadFactory that uses the provided prefix for its thread names and logs uncaught exceptions with the specified Logger.
        Parameters:
        namePrefix - Prefix for this executor thread names
        logger - Logger used to log uncaught exceptions
        Returns:
        the newly created single-threaded Executor
      • newFixedThreadPool

        public static com.google.common.util.concurrent.ListeningExecutorService newFixedThreadPool​(int size,
                                                                                                    String namePrefix,
                                                                                                    org.slf4j.Logger logger)
      • newListeningCachedThreadPool

        public static com.google.common.util.concurrent.ListeningExecutorService newListeningCachedThreadPool​(String namePrefix,
                                                                                                              org.slf4j.Logger logger)
      • newListeningSingleThreadScheduledExecutor

        public static com.google.common.util.concurrent.ListeningScheduledExecutorService newListeningSingleThreadScheduledExecutor​(String namePrefix,
                                                                                                                                    org.slf4j.Logger logger)
      • newListeningScheduledThreadPool

        public static com.google.common.util.concurrent.ListeningScheduledExecutorService newListeningScheduledThreadPool​(int corePoolSize,
                                                                                                                          String namePrefix,
                                                                                                                          org.slf4j.Logger logger)
      • shutdownAndAwaitTermination

        public static void shutdownAndAwaitTermination​(ExecutorService executorService)