public class ThreadUtilities
extends java.lang.Object
Task or Runnable in it, Runnables will be
encapsulated in Task and displayed in the Task Monitor.| Modifier and Type | Method and Description |
|---|---|
static void |
runInBackground(java.lang.Runnable runnable)
Run the runnable in the threadpool.
|
static void |
runInBackground(Task task)
Run the task in the threadpool.
|
static void |
runInDispatchThread(java.lang.Runnable runnable)
Run the runnable in EventDispatch Thread.
|
static void |
runInDispatchThreadAndWait(java.lang.Runnable runnable)
Runs the runnable in EDT through
invokeLater,
but returns only after the runnable is executed. |
static void |
runInDispatchThreadNow(java.lang.Runnable runnable)
Runs the runnable in EDT through
invokeAndWait. |
public static void runInDispatchThread(java.lang.Runnable runnable)
runnable - the runnable to run - it should return something meaningful from
toString() so that we can display it in the Task Monitor.public static void runInDispatchThreadAndWait(java.lang.Runnable runnable)
invokeLater,
but returns only after the runnable is executed.
This method is uninterruptible.
Note the difference from invokeAndWait.
If current thread is not EDT and there are runnables
queued in EDT:
invokeAndWait runs the runnable before them
runnable - the runnable to run - it should return something meaningful from
toString() so that we can display it in the Task Monitor.public static void runInDispatchThreadNow(java.lang.Runnable runnable)
invokeAndWait.
Even if the thread gets interrupted, the call does not return
until the runnable finishes (uninterruptible method).
This method uses EventQueue.invokeAndWait, so
the following remark applies:
If you use invokeAndWait(), make sure that the thread that calls invokeAndWait() does not hold any locks that other threads might need while the call is occurring. From the article: Threads and Swing
runnable - the runnable to run - it should return something meaningful from
toString() so that we can display it in the Task Monitor.public static void runInBackground(java.lang.Runnable runnable)
Taskrunnable - the runnable to run - it should return something meaningful from
toString() so that we can display it in the Task Monitor.runInBackground(Task)public static void runInBackground(Task task)
task - the task to run