Package uk.ac.manchester.spinnaker.utils
Class ThreadUtils
java.lang.Object
uk.ac.manchester.spinnaker.utils.ThreadUtils
public abstract class ThreadUtils extends Object
Utilities for working with threads.
-
Method Summary
Modifier and Type Method Description static void
sleep(long delay)
Recommended way of doing "quiet" sleeps.static String
threadDump()
Produce a dump of what all threads are doing.static boolean
waitfor(Object obj)
Wait for the given object.static boolean
waitfor(Object obj, long timeout)
Wait for the given object.
-
Method Details
-
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
Wait for the given object.- Parameters:
obj
- The object to wait for- Returns:
- True if the wait was interrupted, false otherwise
-
waitfor
Wait for the given object.- Parameters:
obj
- The object to wait fortimeout
- The maximum time to wait, in milliseconds- Returns:
- True if the wait was interrupted, false otherwise
-