public final class ThreadUtil extends Object
java.lang.Thread
-related utility methods.Modifier and Type | Field and Description |
---|---|
static ThreadFactory |
DAEMON_THREAD_FACTORY
Produces daemon threads; handy for "
new ScheduledThreadPoolExecutor {@code (... , ThreadFactory, |
Modifier and Type | Method and Description |
---|---|
static <EX extends Throwable> |
parallel(Iterable<? extends RunnableWhichThrows<EX>> runnables) |
static <EX extends Throwable> |
parallel(Iterable<? extends RunnableWhichThrows<EX>> runnables,
Iterable<Stoppable> stoppables) |
static void |
parallel(Runnable[] runnables,
Iterable<Stoppable> stoppables)
Invokes the
run method of all runnables in parallel threads (including the
current thread). |
static <EX extends Throwable> |
parallel(RunnableWhichThrows<EX> runnable1,
RunnableWhichThrows<EX> runnable2,
Stoppable stoppable)
Executes the two runnables in parallel before it returns.
|
static Stoppable |
runInBackground(Runnable runnable,
String threadName)
Execute the given runnable in a background thread
|
static <EX extends Throwable> |
runInBackground(RunnableWhichThrows<EX> runnable,
String threadName) |
static <R extends RunnableWhichThrows<EX>,EX extends Throwable> |
runInForeground(Iterable<R> runnables)
Runs all but the last of runnables in the background, and the last of runnables in the
foreground.
|
static <EX extends Throwable> |
runInForeground(RunnableWhichThrows<EX> runnable)
Executes the given runnable.
|
public static final ThreadFactory DAEMON_THREAD_FACTORY
new
ScheduledThreadPoolExecutor
(... , ThreadFactory,
...)
", because with the default ThreadFactory
the JVM won't terminate when it shuts down orderly (i.e.
"main()
" returns or "System.exit()
" is invoked).public static Stoppable runInBackground(Runnable runnable, @Nullable String threadName)
public static <EX extends Throwable> Stoppable runInBackground(RunnableWhichThrows<EX> runnable, @Nullable String threadName)
runInBackground(Runnable, String)
public static <EX extends Throwable> void runInForeground(RunnableWhichThrows<EX> runnable) throws EX extends Throwable
EX extends Throwable
public static <EX extends Throwable> void parallel(RunnableWhichThrows<EX> runnable1, RunnableWhichThrows<EX> runnable2, Stoppable stoppable) throws EX extends Throwable
EX extends Throwable
public static <EX extends Throwable> void parallel(Iterable<? extends RunnableWhichThrows<EX>> runnables) throws EX extends Throwable
EX extends Throwable
parallel(Runnable[], Iterable)
public static <EX extends Throwable> void parallel(Iterable<? extends RunnableWhichThrows<EX>> runnables, Iterable<Stoppable> stoppables) throws EX extends Throwable
EX extends Throwable
parallel(Runnable[], Iterable)
public static void parallel(Runnable[] runnables, Iterable<Stoppable> stoppables)
run
method of all runnables in parallel threads (including the
current thread). When the first of these invocations returns, then all threads are interrupt
ed (which awakes them from blocking I/O), and also on all stoppables Stoppable.stop()
is called. When all the threads have been join
ed, this method returns.public static <R extends RunnableWhichThrows<EX>,EX extends Throwable> void runInForeground(Iterable<R> runnables) throws EX extends Throwable
EX extends Throwable
Copyright © 2018 Arno Unkrig. All rights reserved.