- java.lang.Object
-
- ch.bind.philib.lang.ThreadUtil
-
public abstract class ThreadUtil extends Object
- Author:
- Philipp Meinen
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classThreadUtil.ForeverRunnerWrapper for a runnable.
-
Field Summary
Fields Modifier and Type Field Description static ThreadFactoryDEFAULT_THREAD_FACTORY
-
Constructor Summary
Constructors Modifier Constructor Description protectedThreadUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Thread[]createThreads(Runnable[] runnables)Creates a thread for eachRunnablein the provided array.
A standardThreadFactoryis used to create threads.
The newly created threads are not started.static Thread[]createThreads(Runnable[] runnables, ThreadFactory factory)Creates a thread for eachRunnablein the provided array.
The providedThreadFactoryis used to create threads.
The newly created threads are not started.static booleaninterruptAndJoin(Thread t)static booleaninterruptAndJoin(Thread t, long waitTime)static booleaninterruptAndJoinThreads(Thread[] threads)static booleaninterruptAndJoinThreads(Thread[] threads, long waitTimePerThread)static booleaninterruptAndJoinThreads(Collection<? extends Thread> threads)static booleaninterruptAndJoinThreads(Collection<? extends Thread> threads, long waitTimePerThread)static voidsleepUntilMs(long time)static voidstartThreads(Thread[] threads)static voidstartThreads(Collection<? extends Thread> threads)
-
-
-
Field Detail
-
DEFAULT_THREAD_FACTORY
public static final ThreadFactory DEFAULT_THREAD_FACTORY
-
-
Method Detail
-
sleepUntilMs
public static void sleepUntilMs(long time) throws InterruptedException- Throws:
InterruptedException
-
interruptAndJoin
public static boolean interruptAndJoin(Thread t)
- Parameters:
t- the thread which must be interrupted and joined with a default timeout- Returns:
truefor OK,falsein case of an error.
-
interruptAndJoin
public static boolean interruptAndJoin(Thread t, long waitTime)
- Parameters:
t- the thread which must be interruptedwaitTime- a specific timeout for the join operation. A negative or zero value means to no timeout is implied.- Returns:
truefor OK,falsein case of an error.
-
createThreads
public static Thread[] createThreads(Runnable[] runnables)
Creates a thread for eachRunnablein the provided array.
A standardThreadFactoryis used to create threads.
The newly created threads are not started.- Parameters:
runnables- -
-
createThreads
public static Thread[] createThreads(Runnable[] runnables, ThreadFactory factory)
Creates a thread for eachRunnablein the provided array.
The providedThreadFactoryis used to create threads.
The newly created threads are not started.- Parameters:
runnables- -factory- -
-
interruptAndJoinThreads
public static boolean interruptAndJoinThreads(Thread[] threads)
- Parameters:
threads- -- Returns:
trueif all threads were shut down,falseotherwise.
-
interruptAndJoinThreads
public static boolean interruptAndJoinThreads(Thread[] threads, long waitTimePerThread)
- Parameters:
threads- -waitTimePerThread- -- Returns:
trueif all threads were shut down,falseotherwise.
-
interruptAndJoinThreads
public static boolean interruptAndJoinThreads(Collection<? extends Thread> threads)
- Parameters:
threads- -- Returns:
trueif all threads were shut down,falseotherwise.
-
interruptAndJoinThreads
public static boolean interruptAndJoinThreads(Collection<? extends Thread> threads, long waitTimePerThread)
- Parameters:
threads- -waitTimePerThread- -- Returns:
trueif all threads were shut down,falseotherwise.
-
startThreads
public static void startThreads(Thread[] threads)
-
startThreads
public static void startThreads(Collection<? extends Thread> threads)
-
-