Class ThreadUtils
java.lang.Object
org.deltava.util.ThreadUtils
A utility class to handle Thread operations.
- Since:
- 1.0
- Version:
- 12.1
- Author:
- Luke
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanA null-safe way to determine if a Thread is alive.static booleanA null-safe way to determine if a Future is still executing.static voidA null-safe way of killing a Thread that swallows thread lifecycle exceptions.static voidkill(Collection<Thread> threads, long waitTime) A null-safe way of killing a number of threads that swallows thread lifecycle exceptions.static voidsleep(long sleepTime) Causes a thread to sleep, swallowing exceptions.static voidWaits for a running Thread to complete.static voidWaits up to a certain period of time for a Future to complete.static voidwaitOnFutures(Collection<Future<?>> futures) Waits for a collection of operations to complete.static voidwaitOnPool(Collection<? extends Thread> tPool) Waits for a Thread pool to complete.
-
Method Details
-
isAlive
A null-safe way to determine if a Thread is alive.- Parameters:
t- the Thread- Returns:
- TRUE if the Thread is alive, otherwise FALSE
-
isAlive
A null-safe way to determine if a Future is still executing.- Parameters:
f- the FUture- Returns:
- TRUE if the Future is still Active, otherwise FALSE
-
kill
A null-safe way of killing a Thread that swallows thread lifecycle exceptions.- Parameters:
t- the Thread to killwaitTime- the time to wait for the thread to die in milliseconds
-
kill
A null-safe way of killing a number of threads that swallows thread lifecycle exceptions.- Parameters:
threads- a Collection of Threads to killwaitTime- 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
Waits for a running Thread to complete.- Parameters:
t- the ThreadmaxTime- the maximum number of milliseconds to wait
-
waitFor
Waits up to a certain period of time for a Future to complete.- Parameters:
f- the FuturemaxTime- the maximum time in milliseconds
-
waitOnPool
Waits for a Thread pool to complete.- Parameters:
tPool- a Collection of Threads
-
waitOnFutures
Waits for a collection of operations to complete.- Parameters:
futures- a Collection of Futures
-