Class ThreadUtils
java.lang.Object
org.deltava.util.ThreadUtils
A utility class to handle Thread operations.
- Since:
- 1.0
- Version:
- 11.1
- Author:
- Luke
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
A null-safe way to determine if a Thread is alive.static void
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
Waits for a running Thread to complete.static void
waitOnFutures
(Collection<Future<?>> futures) Waits for a collection of operations to complete.static void
waitOnPool
(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
-
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
-
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
-