public final class ThreadPool
extends java.lang.Object
Executor
that executes code on the UI Thread and an ExecutorService
that allows
for code to be executed on a background thread via a Threadpool. This class does not require a configuration (i.e. is
usable immediately without calling init(Config)
), but if you'd like to override the default
behavior, you may do so as long as the initialization is done before any tasks have been submitted for background
execution.Modifier and Type | Class and Description |
---|---|
static class |
ThreadPool.Config
Threadpool configuration.
|
Constructor and Description |
---|
ThreadPool() |
Modifier and Type | Method and Description |
---|---|
static java.util.concurrent.ExecutorService |
background()
Get the background
ExecutorService |
static void |
bg(java.lang.Runnable runnable)
Submit a
Runnable to be executed on a background thread |
static void |
fg(java.lang.Runnable runnable)
Submit a
Runnable to be executed on the UI thread. |
static java.util.concurrent.Executor |
foreground()
Get the foreground (UI Thread)
Executor |
static void |
init(ThreadPool.Config config)
Initialize the Threadpool with non-default values.
|
static <T> java.util.concurrent.Future<T> |
submit(java.util.concurrent.Callable<T> callable)
Executes a
Runnable on the background thread. |
static java.util.concurrent.Future<?> |
submit(java.lang.Runnable runnable)
Executes a
Runnable on the background thread. |
static <T> java.util.concurrent.Future<T> |
submit(java.lang.Runnable runnable,
T result)
Executes a
Runnable on the background thread. |
public static void fg(java.lang.Runnable runnable)
Runnable
to be executed on the UI thread.runnable
- task to executepublic static void bg(java.lang.Runnable runnable)
Runnable
to be executed on a background threadrunnable
- public static java.util.concurrent.Future<?> submit(java.lang.Runnable runnable)
Runnable
on the background thread.
See ExecutorService.submit(Runnable)
public static <T> java.util.concurrent.Future<T> submit(java.util.concurrent.Callable<T> callable)
Runnable
on the background thread.
See ExecutorService.submit(Callable)
public static <T> java.util.concurrent.Future<T> submit(java.lang.Runnable runnable, T result)
Runnable
on the background thread.
See ExecutorService.submit(Runnable, Object)
public static java.util.concurrent.ExecutorService background()
ExecutorService
ExecutorService
public static java.util.concurrent.Executor foreground()
Executor
Executor
public static void init(ThreadPool.Config config)
config
- Threadpool configurationjava.lang.IllegalStateException
- if the Threadpool has already been initialized via either calling init(Config)
or background()