public class ThreadUtil extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
ThreadUtil.CaughtRunnable
This class is used to catch exception in the EDT.
|
Modifier and Type | Field and Description |
---|---|
static int |
MAX_PRIORITY
The maximum priority that a thread can have.
|
static int |
MIN_PRIORITY
The minimum priority that a thread can have.
|
static int |
NORM_PRIORITY
The default priority that is assigned to a thread.
|
Constructor and Description |
---|
ThreadUtil() |
Modifier and Type | Method and Description |
---|---|
static <T> java.util.concurrent.Future<T> |
bgRun(java.util.concurrent.Callable<T> callable)
Adds background processing (low priority) of specified Callable task.
|
static <T> java.util.concurrent.Future<T> |
bgRun(java.util.concurrent.Callable<T> callable,
boolean onEDT)
Deprecated.
Use
bgRun(Callable) and invokeNow(Callable) separately instead. |
static boolean |
bgRun(java.lang.Runnable runnable)
Adds background processing (low priority) of specified Runnable.
|
static boolean |
bgRun(java.lang.Runnable runnable,
boolean onEDT)
Deprecated.
Use
bgRun(Runnable) instead and invokeNow(Runnable) separately. |
static <T> java.util.concurrent.Future<T> |
bgRunSingle(java.util.concurrent.Callable<T> callable)
Adds single processing (low priority) of specified Callable task.
|
static <T> java.util.concurrent.Future<T> |
bgRunSingle(java.util.concurrent.Callable<T> callable,
boolean onEDT)
Deprecated.
Use
runSingle(Callable) and invokeNow(Callable) separately
instead. |
static boolean |
bgRunSingle(java.lang.Runnable runnable)
Adds single processing (low priority) of specified Runnable.
|
static boolean |
bgRunSingle(java.lang.Runnable runnable,
boolean onEDT)
Deprecated.
Use
runSingle(Runnable) instead and invokeNow(Runnable) separately. |
static void |
bgRunWait(java.lang.Runnable runnable)
Deprecated.
Use
bgRun(Runnable) instead and check for acceptance. |
static java.util.concurrent.ExecutorService |
createThreadPool(java.lang.String name)
Create a thread pool with the given name.
|
static int |
getActiveBgTaskCount()
Return the number of active background tasks.
|
static boolean |
hasWaitingBgSingleTask(java.util.concurrent.Callable<?> callable)
Return true if the specified callable is waiting to be processed
in single scheme background processing (low priority). |
static boolean |
hasWaitingBgSingleTask(java.lang.Runnable runnable)
Return true if the specified runnable is waiting to be processed
in single scheme background processing (low priority). |
static boolean |
hasWaitingBgTask(java.util.concurrent.Callable<?> callable)
Return true if the specified callable is waiting to be processed in background processing.
|
static boolean |
hasWaitingBgTask(java.lang.Runnable runnable)
Return true if the specified runnable is waiting to be processed in background processing.
|
static boolean |
hasWaitingSingleTask(java.util.concurrent.Callable<?> callable)
Return true if the specified callable is waiting to be processed
in single scheme background processing (normal priority). |
static boolean |
hasWaitingSingleTask(java.lang.Runnable runnable)
Return true if the specified runnable is waiting to be processed
in single scheme background processing (normal priority). |
static void |
invoke(java.lang.Runnable runnable,
boolean wait)
Invoke the specified
Runnable on the AWT event dispatching thread. |
static void |
invokeAndWait(java.lang.Runnable runnable)
Deprecated.
Use
invokeNow(Runnable) instead |
static <T> java.util.concurrent.Future<T> |
invokeLater(java.util.concurrent.Callable<T> callable,
boolean forceLater)
Invoke the specified
Callable on the AWT event dispatching thread. |
static void |
invokeLater(java.lang.Runnable runnable)
Invoke the specified
Runnable on the AWT event dispatching thread. |
static void |
invokeLater(java.lang.Runnable runnable,
boolean forceLater)
Invoke the specified
Runnable on the AWT event dispatching thread. |
static <T> T |
invokeNow(java.util.concurrent.Callable<T> callable)
Invoke the specified
Callable on the AWT event dispatching thread now and return
the result. |
static void |
invokeNow(java.lang.Runnable runnable)
Invoke the specified
Runnable on the AWT event dispatching thread now and wait
until completion. |
static boolean |
isEventDispatchThread() |
static boolean |
isShutdownAndTerminated()
Return true if all background runner are shutdown and terminated.
|
static <T> java.util.concurrent.Future<T> |
runSingle(java.util.concurrent.Callable<T> callable)
Add single processing (normal priority) of specified Callable task.
|
static boolean |
runSingle(java.lang.Runnable runnable)
Add single processing (normal priority) of specified Runnable.
|
static void |
shutdown()
Shutdown all background runner.
|
static void |
sleep(int milli)
Same as
Thread.sleep(long) except Exception is caught and ignored. |
static void |
sleep(long milli)
Same as
Thread.sleep(long) except Exception is caught and ignored. |
public static final int MIN_PRIORITY
public static final int NORM_PRIORITY
public static final int MAX_PRIORITY
public ThreadUtil()
public static void shutdown()
public static boolean isShutdownAndTerminated()
public static boolean isEventDispatchThread()
public static void invoke(java.lang.Runnable runnable, boolean wait)
Runnable
on the AWT event dispatching thread.wait
- If set to true, the method wait until completion, in this case you have to take
attention to not cause any dead lock.invokeLater(Runnable)
,
invokeNow(Runnable)
@Deprecated public static void invokeAndWait(java.lang.Runnable runnable)
invokeNow(Runnable)
insteadpublic static void invokeNow(java.lang.Runnable runnable)
Runnable
on the AWT event dispatching thread now and wait
until completion.invokeNow(Callable)
instead.public static void invokeLater(java.lang.Runnable runnable)
Runnable
on the AWT event dispatching thread.Runnable
is executed immediately else it will
be executed later.invokeLater(Runnable, boolean)
public static void invokeLater(java.lang.Runnable runnable, boolean forceLater)
Runnable
on the AWT event dispatching thread.forceLater
parameter the Runnable
can be executed
immediately if we are on the EDT.forceLater
- If true
the Runnable
is forced to execute later even if we
are on the Swing EDT.public static <T> T invokeNow(java.util.concurrent.Callable<T> callable) throws java.lang.Exception
Callable
on the AWT event dispatching thread now and return
the result.null
when a Throwable
exception happen.java.lang.InterruptedException
- if the current thread was interrupted while waitingjava.lang.Exception
- if the computation threw an exceptionpublic static <T> java.util.concurrent.Future<T> invokeLater(java.util.concurrent.Callable<T> callable, boolean forceLater)
Callable
on the AWT event dispatching thread.forceLater
parameter the Callable
can be executed
immediately if we are on the EDT.forceLater
- If true
the Callable
is forced to execute later even if we
are on the EDT.@Deprecated public static boolean bgRun(java.lang.Runnable runnable, boolean onEDT)
bgRun(Runnable)
@Deprecated public static void bgRunWait(java.lang.Runnable runnable)
bgRun(Runnable)
instead and check for acceptance.public static boolean bgRun(java.lang.Runnable runnable)
false
if background process queue is full.@Deprecated public static <T> java.util.concurrent.Future<T> bgRun(java.util.concurrent.Callable<T> callable, boolean onEDT)
bgRun(Callable)
public static <T> java.util.concurrent.Future<T> bgRun(java.util.concurrent.Callable<T> callable)
null
if
background process queue is full.@Deprecated public static boolean bgRunSingle(java.lang.Runnable runnable, boolean onEDT)
bgRunSingle(Runnable)
@Deprecated public static <T> java.util.concurrent.Future<T> bgRunSingle(java.util.concurrent.Callable<T> callable, boolean onEDT)
bgRunSingle(Callable)
public static boolean bgRunSingle(java.lang.Runnable runnable)
Runnable
instance is already pending in single processes queue then
nothing is done.false
if single processes queue is full.public static <T> java.util.concurrent.Future<T> bgRunSingle(java.util.concurrent.Callable<T> callable)
Callable
instance is already pending in single processes queue then
nothing is done.null
if
single processes queue is full.public static boolean runSingle(java.lang.Runnable runnable)
Runnable
instance is already pending in single processes queue then
nothing is done.false
if single processes queue is full.public static <T> java.util.concurrent.Future<T> runSingle(java.util.concurrent.Callable<T> callable)
Callable
instance is already pending in single processes queue then
nothing is done.null
if
single processes queue is full.public static boolean hasWaitingBgTask(java.lang.Runnable runnable)
public static boolean hasWaitingBgTask(java.util.concurrent.Callable<?> callable)
public static boolean hasWaitingBgSingleTask(java.lang.Runnable runnable)
public static boolean hasWaitingBgSingleTask(java.util.concurrent.Callable<?> callable)
public static boolean hasWaitingSingleTask(java.lang.Runnable runnable)
public static boolean hasWaitingSingleTask(java.util.concurrent.Callable<?> callable)
public static int getActiveBgTaskCount()
public static java.util.concurrent.ExecutorService createThreadPool(java.lang.String name)
Processor.Processor(int, int, int)
public static void sleep(long milli)
Thread.sleep(long)
except Exception is caught and ignored.public static void sleep(int milli)
Thread.sleep(long)
except Exception is caught and ignored.