Class ThreadUtil


  • public abstract class ThreadUtil
    extends Object
    Author:
    Philipp Meinen
    • Field Detail

      • DEFAULT_THREAD_FACTORY

        public static final ThreadFactory DEFAULT_THREAD_FACTORY
    • Constructor Detail

      • ThreadUtil

        protected ThreadUtil()
    • Method Detail

      • interruptAndJoin

        public static boolean interruptAndJoin​(Thread t)
        Parameters:
        t - the thread which must be interrupted and joined with a default timeout
        Returns:
        true for OK, false in case of an error.
      • interruptAndJoin

        public static boolean interruptAndJoin​(Thread t,
                                               long waitTime)
        Parameters:
        t - the thread which must be interrupted
        waitTime - a specific timeout for the join operation. A negative or zero value means to no timeout is implied.
        Returns:
        true for OK, false in case of an error.
      • createThreads

        public static Thread[] createThreads​(Runnable[] runnables)
        Creates a thread for each Runnable in the provided array.
        A standard ThreadFactory is used to create threads.
        The newly created threads are not started.
        Parameters:
        runnables - -
      • createThreads

        public static Thread[] createThreads​(Runnable[] runnables,
                                             ThreadFactory factory)
        Creates a thread for each Runnable in the provided array.
        The provided ThreadFactory is used to create threads.
        The newly created threads are not started.
        Parameters:
        runnables - -
        factory - -
      • interruptAndJoinThreads

        public static boolean interruptAndJoinThreads​(Thread[] threads)
        Parameters:
        threads - -
        Returns:
        true if all threads were shut down, false otherwise.
      • interruptAndJoinThreads

        public static boolean interruptAndJoinThreads​(Thread[] threads,
                                                      long waitTimePerThread)
        Parameters:
        threads - -
        waitTimePerThread - -
        Returns:
        true if all threads were shut down, false otherwise.
      • interruptAndJoinThreads

        public static boolean interruptAndJoinThreads​(Collection<? extends Thread> threads)
        Parameters:
        threads - -
        Returns:
        true if all threads were shut down, false otherwise.
      • interruptAndJoinThreads

        public static boolean interruptAndJoinThreads​(Collection<? extends Thread> threads,
                                                      long waitTimePerThread)
        Parameters:
        threads - -
        waitTimePerThread - -
        Returns:
        true if all threads were shut down, false otherwise.
      • startThreads

        public static void startThreads​(Thread[] threads)
      • startThreads

        public static void startThreads​(Collection<? extends Thread> threads)