Class Concurrency


  • public final class Concurrency
    extends Object
    Helper methods for concurrency related things.
    • Method Detail

      • waitForTermination

        public static void waitForTermination​(ExecutorService executor)
        Wait uninterruptibly until an ExecutorService has shutdown. It also ensures full memory visibility of everything that was done in the callables.

        Interrupting the thread will have no effect, but this method will set the thread's interrupted flag in this case.

      • createThreadPool

        public static ExecutorService createThreadPool()
        Creates a thread pool of fixed size. Size is determined by processors available to the JVM.
        Returns:
        thread pool
      • createThreadPool

        public static ExecutorService createThreadPool​(ThreadFactory threadFactory)
        Creates a thread pool of fixed size. Size is determined by processors available to the JVM.
        Parameters:
        threadFactory - The thread factory to be used.
        Returns:
        thread pool
      • newThread

        public static Thread newThread​(String name,
                                       Runnable r)
        Create a new non-daemon thread with a name. Compared to creating threads manually, this has the advantage that the thread will be created with the default settings. By default, Java lets threads inherit some settings from the creating thread.
        Parameters:
        name - The name of the new thread.
        r - The Runnable to execute in the new thread.
        Returns:
        A new thread, not yet started.
      • newDaemonThread

        public static Thread newDaemonThread​(String name,
                                             Runnable r)
        Create a new daemon thread with a name. Compared to creating threads manually, this has the advantage that the thread will be created with the default settings. By default, Java lets threads inherit some settings from the creating thread.
        Parameters:
        name - The name of the new thread.
        r - The Runnable to execute in the new thread.
        Returns:
        A new daemon thread, not yet started.