Class ThreadUtils

java.lang.Object
uk.ac.manchester.spinnaker.utils.ThreadUtils

public abstract class ThreadUtils
extends Object
Utilities for working with threads.
  • Method Details

    • threadDump

      public static String threadDump()
      Produce a dump of what all threads are doing. Useful for debugging as it means you can get a dump of threads programmatically at the time when the problem is likely to be on some thread's stack.
      Returns:
      The dump, as a multi-line string.
    • sleep

      public static void sleep​(long delay)
      Recommended way of doing "quiet" sleeps.
      Parameters:
      delay - How long to sleep for, in milliseconds.
      See Also:
      Stack Overflow Question: When does Java's Thread.sleep throw InterruptedException?
    • waitfor

      public static boolean waitfor​(Object obj)
      Wait for the given object.
      Parameters:
      obj - The object to wait for
      Returns:
      True if the wait was interrupted, false otherwise
    • waitfor

      public static boolean waitfor​(Object obj, long timeout)
      Wait for the given object.
      Parameters:
      obj - The object to wait for
      timeout - The maximum time to wait, in milliseconds
      Returns:
      True if the wait was interrupted, false otherwise