Class ThreadUtils

java.lang.Object
org.deltava.util.ThreadUtils

public class ThreadUtils extends Object
A utility class to handle Thread operations.
Since:
1.0
Version:
11.1
Author:
Luke
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    A null-safe way to determine if a Thread is alive.
    static void
    kill(Thread t, long waitTime)
    A null-safe way of killing a Thread that swallows thread lifecycle exceptions.
    static void
    kill(Collection<Thread> threads, long waitTime)
    A null-safe way of killing a number of threads that swallows thread lifecycle exceptions.
    static void
    sleep(long sleepTime)
    Causes a thread to sleep, swallowing exceptions.
    static void
    waitFor(Thread t, long maxTime)
    Waits for a running Thread to complete.
    static void
    Waits for a collection of operations to complete.
    static void
    waitOnPool(Collection<? extends Thread> tPool)
    Waits for a Thread pool to complete.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • isAlive

      public static boolean isAlive(Thread t)
      A null-safe way to determine if a Thread is alive.
      Parameters:
      t - the Thread
      Returns:
      TRUE if the Thread is alive, otherwise FALSE
    • kill

      public static void kill(Thread t, long waitTime)
      A null-safe way of killing a Thread that swallows thread lifecycle exceptions.
      Parameters:
      t - the Thread to kill
      waitTime - the time to wait for the thread to die in milliseconds
    • kill

      public static void kill(Collection<Thread> threads, long waitTime)
      A null-safe way of killing a number of threads that swallows thread lifecycle exceptions.
      Parameters:
      threads - a Collection of Threads to kill
      waitTime - the time to wait for the thread to die in milliseconds
    • sleep

      public static void sleep(long sleepTime)
      Causes a thread to sleep, swallowing exceptions.
      Parameters:
      sleepTime - the duration to sleep for in milliseconds
    • waitFor

      public static void waitFor(Thread t, long maxTime)
      Waits for a running Thread to complete.
      Parameters:
      t - the Thread
      maxTime - the maximum number of milliseconds to wait
    • waitOnPool

      public static void waitOnPool(Collection<? extends Thread> tPool)
      Waits for a Thread pool to complete.
      Parameters:
      tPool - a Collection of Threads
    • waitOnFutures

      public static void waitOnFutures(Collection<Future<?>> futures)
      Waits for a collection of operations to complete.
      Parameters:
      futures - a Collection of Futures