de.unkrig.commons.lang
Class ThreadUtil

java.lang.Object
  extended by de.unkrig.commons.lang.ThreadUtil

public final class ThreadUtil
extends java.lang.Object

Various java.lang.Thread-related utility methods.


Method Summary
static
<EX extends java.lang.Exception>
void
parallel(java.lang.Iterable<? extends RunnableWhichThrows<EX>> runnables)
           
static
<EX extends java.lang.Exception>
void
parallel(java.lang.Iterable<? extends RunnableWhichThrows<EX>> runnables, java.lang.Iterable<Stoppable> stoppables)
           
static void parallel(java.lang.Runnable[] runnables, java.lang.Iterable<Stoppable> stoppables)
          Invokes the run method of all runnables in parallel threads (including the current thread).
static
<EX extends java.lang.Exception>
void
parallel(RunnableWhichThrows<EX> runnable1, RunnableWhichThrows<EX> runnable2, Stoppable stoppable)
          Executes the two runnables in parallel before it returns.
static Stoppable runInBackground(java.lang.Runnable runnable, java.lang.String threadName)
          Execute the given runnable in a background thread
static
<EX extends java.lang.Exception>
Stoppable
runInBackground(RunnableWhichThrows<EX> runnable, java.lang.String threadName)
           
static
<R extends RunnableWhichThrows<EX>,EX extends java.lang.Exception>
void
runInForeground(java.lang.Iterable<R> runnables)
          Runs all but the last of runnables in the background, and the last of runnables in the foreground.
static
<EX extends java.lang.Exception>
void
runInForeground(RunnableWhichThrows<EX> runnable)
          Executes the given runnable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

runInBackground

public static Stoppable runInBackground(java.lang.Runnable runnable,
                                        @Nullable
                                        java.lang.String threadName)
Execute the given runnable in a background thread

Returns:
The beckground runnable can be interrupted through this object

runInBackground

public static <EX extends java.lang.Exception> Stoppable runInBackground(RunnableWhichThrows<EX> runnable,
                                                                         @Nullable
                                                                         java.lang.String threadName)
See Also:
runInBackground(Runnable, String)

runInForeground

public static <EX extends java.lang.Exception> void runInForeground(RunnableWhichThrows<EX> runnable)
                            throws EX extends java.lang.Exception
Executes the given runnable.

Throws:
EX extends java.lang.Exception

parallel

public static <EX extends java.lang.Exception> void parallel(RunnableWhichThrows<EX> runnable1,
                                                             RunnableWhichThrows<EX> runnable2,
                                                             Stoppable stoppable)
                     throws EX extends java.lang.Exception
Executes the two runnables in parallel before it returns.

Throws:
EX extends java.lang.Exception

parallel

public static <EX extends java.lang.Exception> void parallel(java.lang.Iterable<? extends RunnableWhichThrows<EX>> runnables)
                     throws EX extends java.lang.Exception
Throws:
EX extends java.lang.Exception
See Also:
parallel(Runnable[], Iterable)

parallel

public static <EX extends java.lang.Exception> void parallel(java.lang.Iterable<? extends RunnableWhichThrows<EX>> runnables,
                                                             java.lang.Iterable<Stoppable> stoppables)
                     throws EX extends java.lang.Exception
Throws:
EX extends java.lang.Exception
See Also:
parallel(Runnable[], Iterable)

parallel

public static void parallel(java.lang.Runnable[] runnables,
                            java.lang.Iterable<Stoppable> stoppables)
Invokes the run method of all runnables in parallel threads (including the current thread). When the first of these invocations returns, then all threads are interrupted (which awakes them from blocking I/O), and also on all stoppables Stoppable.stop() is called. When all the threads have been joined, this method returns.


runInForeground

public static <R extends RunnableWhichThrows<EX>,EX extends java.lang.Exception> void runInForeground(java.lang.Iterable<R> runnables)
                            throws EX extends java.lang.Exception
Runs all but the last of runnables in the background, and the last of runnables in the foreground.

Throws:
EX extends java.lang.Exception