Package no.digipost

Class DiggConcurrent

java.lang.Object
no.digipost.DiggConcurrent

public class DiggConcurrent extends Object
  • Method Details

    • fixedThreadPool

      public static ExecutorService fixedThreadPool(int threadAmount, String name)
    • singleThreaded

      public static ExecutorService singleThreaded(String name)
    • scheduledSingleThreaded

      public static ScheduledExecutorService scheduledSingleThreaded(String name)
    • scheduled

      public static ScheduledExecutorService scheduled(int threadAmount, String name)
    • threadNamingFactory

      public static ThreadFactory threadNamingFactory(String threadBaseName)
      Create a thread factory based on Executors.defaultThreadFactory(), but naming the created threads using the given threadBaseName and an incrementing number for each thread created by the factory. The threads will have names on the form threadBaseName-N.
      Parameters:
      threadBaseName - the base name for threads created by the factory.
    • threadNamingFactory

      public static ThreadFactory threadNamingFactory(LongFunction<String> threadName)
      Create a thread factory based on Executors.defaultThreadFactory(), but naming the created threads using the result of the given given long -> String function, which argument is the number of the created thread.
      Parameters:
      threadName - function used for naming each thread created by the factory.
    • threadNamingFactory

      public static ThreadFactory threadNamingFactory(LongFunction<String> threadName, ThreadFactory backingFactory)
      Create a thread factory delegating to the given backingFactory for creating new threads, but naming the created threads using the result of the given given long -> String function, which argument is the number of the created thread.
      Parameters:
      threadName - function used for naming each thread created by the factory.
      backingFactory - the factory used for creating new threads.
    • externallyManaged

      public static ExecutorService externallyManaged(ExecutorService executor)
      Wraps another ExecutorService as an "externally managed executor service", which will discard any invocations of the methods used to manage the lifecycle of the ExecutorService itself. This includes the methods: An externally managed executor will not be attempted shut down by ensureShutdown(ExecutorService, Duration).
    • isExternallyManaged

      public static boolean isExternallyManaged(ExecutorService executor)
      Determine if the given ExecutorService is marked as externally managed.
    • ensureShutdown

      public static void ensureShutdown(ExecutorService executor, Duration timeoutBeforeForcefulShutdown)
      Perform an orderly shutdown, trying to wait for any currently running tasks to finish, or else forcefully shutdown the executor if the tasks are not able to finish their work within the given timeout duration. The ensureShutdown(String, ExecutorService, Duration) method is preferred over this.
      Parameters:
      executor - the ExecutorService to shut down.
      timeoutBeforeForcefulShutdown - the maximum amount of time to wait for tasks to finish before forcefully shutting down the executor.
    • ensureShutdown

      public static void ensureShutdown(String executorName, ExecutorService executor, Duration timeoutBeforeForcefulShutdown)
      Perform an orderly shutdown, trying to wait for any currently running tasks to finish, or else forcefully shutdown the executor if the tasks are not able to finish their work within the given timeout duration.
      Parameters:
      executorName - a descriptive name of the executor to shut down, used for logging.
      executor - the ExecutorService to shut down.
      timeoutBeforeForcefulShutdown - the maximum amount of time to wait for tasks to finish before forcefully shutting down the executor.