public class ThreadUtils
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
ThreadUtils.BlockingOperation
Utility interface to be used with executeUninterruptibly() to wait for blocking operations
to complete without getting interrupted..
|
static class |
ThreadUtils.ThreadChecker
Utility class to be used for checking that a method is called on the correct thread.
|
Constructor and Description |
---|
ThreadUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
awaitUninterruptibly(java.util.concurrent.CountDownLatch latch) |
static boolean |
awaitUninterruptibly(java.util.concurrent.CountDownLatch barrier,
long timeoutMs) |
static void |
checkIsOnMainThread()
Throws exception if called from other than main thread.
|
static java.lang.StackTraceElement[] |
concatStackTraces(java.lang.StackTraceElement[] inner,
java.lang.StackTraceElement[] outer) |
static void |
executeUninterruptibly(ThreadUtils.BlockingOperation operation)
Utility method to make sure a blocking operation is executed to completion without getting
interrupted.
|
static <V> V |
invokeAtFrontUninterruptibly(android.os.Handler handler,
java.util.concurrent.Callable<V> callable)
Post |callable| to |handler| and wait for the result.
|
static void |
invokeAtFrontUninterruptibly(android.os.Handler handler,
java.lang.Runnable runner)
Post |runner| to |handler|, at the front, and wait for completion.
|
static boolean |
isOnUiThread() |
static void |
joinUninterruptibly(java.lang.Thread thread) |
static boolean |
joinUninterruptibly(java.lang.Thread thread,
long timeoutMs) |
static void |
postOnUiThread(java.lang.Runnable runnable,
long delayMills)
Posts the given
Runnable on the UI thread. |
static void |
runOnUiThread(java.lang.Runnable runnable)
Runs the given
Runnable on the UI thread. |
static void |
waitUninterruptibly(java.lang.Object object) |
public static boolean isOnUiThread()
true
if the current thread is the UI thread.public static void runOnUiThread(java.lang.Runnable runnable)
Runnable
on the UI thread.public static void postOnUiThread(java.lang.Runnable runnable, long delayMills)
Runnable
on the UI thread.public static void checkIsOnMainThread()
public static void executeUninterruptibly(ThreadUtils.BlockingOperation operation)
public static boolean joinUninterruptibly(java.lang.Thread thread, long timeoutMs)
public static void joinUninterruptibly(java.lang.Thread thread)
public static void awaitUninterruptibly(java.util.concurrent.CountDownLatch latch)
public static boolean awaitUninterruptibly(java.util.concurrent.CountDownLatch barrier, long timeoutMs)
public static void waitUninterruptibly(java.lang.Object object)
public static <V> V invokeAtFrontUninterruptibly(android.os.Handler handler, java.util.concurrent.Callable<V> callable)
public static void invokeAtFrontUninterruptibly(android.os.Handler handler, java.lang.Runnable runner)
public static java.lang.StackTraceElement[] concatStackTraces(java.lang.StackTraceElement[] inner, java.lang.StackTraceElement[] outer)