public final class GlideExecutor extends Object implements ExecutorService
ThreadPoolExecutor
for running jobs in Glide.Modifier and Type | Class and Description |
---|---|
static interface |
GlideExecutor.UncaughtThrowableStrategy
A strategy for handling unexpected and uncaught
Throwable s thrown by futures run on the
pool. |
Modifier and Type | Method and Description |
---|---|
boolean |
awaitTermination(long timeout,
TimeUnit unit) |
static int |
calculateBestThreadCount()
Determines the number of cores available on the device.
|
void |
execute(Runnable command) |
<T> List<Future<T>> |
invokeAll(Collection<? extends Callable<T>> tasks) |
<T> List<Future<T>> |
invokeAll(Collection<? extends Callable<T>> tasks,
long timeout,
TimeUnit unit) |
<T> T |
invokeAny(Collection<? extends Callable<T>> tasks) |
<T> T |
invokeAny(Collection<? extends Callable<T>> tasks,
long timeout,
TimeUnit unit) |
boolean |
isShutdown() |
boolean |
isTerminated() |
static GlideExecutor |
newAnimationExecutor()
Returns a new cached thread pool that defaults to either one or two threads depending on the
number of available cores to use when loading frames of animations.
|
static GlideExecutor |
newAnimationExecutor(int threadCount,
GlideExecutor.UncaughtThrowableStrategy uncaughtThrowableStrategy)
Returns a new cached thread pool with the given thread count and
GlideExecutor.UncaughtThrowableStrategy to use when loading frames of animations. |
static GlideExecutor |
newDiskCacheExecutor()
Returns a new fixed thread pool with the default thread count returned from
calculateBestThreadCount() , the DEFAULT_DISK_CACHE_EXECUTOR_NAME thread name
prefix, and the
GlideExecutor.UncaughtThrowableStrategy.DEFAULT
uncaught throwable strategy. |
static GlideExecutor |
newDiskCacheExecutor(GlideExecutor.UncaughtThrowableStrategy uncaughtThrowableStrategy)
Returns a new fixed thread pool with the default thread count returned from
calculateBestThreadCount() , the DEFAULT_DISK_CACHE_EXECUTOR_NAME thread name
prefix, and a custom
GlideExecutor.UncaughtThrowableStrategy
uncaught throwable strategy. |
static GlideExecutor |
newDiskCacheExecutor(int threadCount,
String name,
GlideExecutor.UncaughtThrowableStrategy uncaughtThrowableStrategy)
Returns a new fixed thread pool with the given thread count, thread name prefix,
and
GlideExecutor.UncaughtThrowableStrategy . |
static GlideExecutor |
newSourceExecutor()
Returns a new fixed thread pool with the default thread count returned from
calculateBestThreadCount() , the DEFAULT_SOURCE_EXECUTOR_NAME thread name
prefix, and the
GlideExecutor.UncaughtThrowableStrategy.DEFAULT
uncaught throwable strategy. |
static GlideExecutor |
newSourceExecutor(GlideExecutor.UncaughtThrowableStrategy uncaughtThrowableStrategy)
Returns a new fixed thread pool with the default thread count returned from
calculateBestThreadCount() , the DEFAULT_SOURCE_EXECUTOR_NAME thread name
prefix, and a custom
GlideExecutor.UncaughtThrowableStrategy
uncaught throwable strategy. |
static GlideExecutor |
newSourceExecutor(int threadCount,
String name,
GlideExecutor.UncaughtThrowableStrategy uncaughtThrowableStrategy)
Returns a new fixed thread pool with the given thread count, thread name prefix,
and
GlideExecutor.UncaughtThrowableStrategy . |
static GlideExecutor |
newUnlimitedSourceExecutor()
Returns a new unlimited thread pool with zero core thread count to make sure no threads are
created by default,
KEEP_ALIVE_TIME_MS keep alive
time, the SOURCE_UNLIMITED_EXECUTOR_NAME thread name prefix, the
GlideExecutor.UncaughtThrowableStrategy.DEFAULT
uncaught throwable strategy, and the SynchronousQueue since using default unbounded
blocking queue, for example, PriorityBlockingQueue effectively won't create more than
corePoolSize threads. |
void |
shutdown() |
List<Runnable> |
shutdownNow() |
<T> Future<T> |
submit(Callable<T> task) |
Future<?> |
submit(Runnable task) |
<T> Future<T> |
submit(Runnable task,
T result) |
String |
toString() |
public static GlideExecutor newDiskCacheExecutor()
calculateBestThreadCount()
, the DEFAULT_DISK_CACHE_EXECUTOR_NAME
thread name
prefix, and the
GlideExecutor.UncaughtThrowableStrategy.DEFAULT
uncaught throwable strategy.
Disk cache executors do not allow network operations on their threads.
public static GlideExecutor newDiskCacheExecutor(GlideExecutor.UncaughtThrowableStrategy uncaughtThrowableStrategy)
calculateBestThreadCount()
, the DEFAULT_DISK_CACHE_EXECUTOR_NAME
thread name
prefix, and a custom
GlideExecutor.UncaughtThrowableStrategy
uncaught throwable strategy.
Disk cache executors do not allow network operations on their threads.
uncaughtThrowableStrategy
- The GlideExecutor.UncaughtThrowableStrategy
to use to
handle uncaught exceptions.public static GlideExecutor newDiskCacheExecutor(int threadCount, String name, GlideExecutor.UncaughtThrowableStrategy uncaughtThrowableStrategy)
GlideExecutor.UncaughtThrowableStrategy
.
Disk cache executors do not allow network operations on their threads.
threadCount
- The number of threads.name
- The prefix for each thread name.uncaughtThrowableStrategy
- The GlideExecutor.UncaughtThrowableStrategy
to use to
handle uncaught exceptions.public static GlideExecutor newSourceExecutor()
calculateBestThreadCount()
, the DEFAULT_SOURCE_EXECUTOR_NAME
thread name
prefix, and the
GlideExecutor.UncaughtThrowableStrategy.DEFAULT
uncaught throwable strategy.
Source executors allow network operations on their threads.
public static GlideExecutor newSourceExecutor(GlideExecutor.UncaughtThrowableStrategy uncaughtThrowableStrategy)
calculateBestThreadCount()
, the DEFAULT_SOURCE_EXECUTOR_NAME
thread name
prefix, and a custom
GlideExecutor.UncaughtThrowableStrategy
uncaught throwable strategy.
Source executors allow network operations on their threads.
uncaughtThrowableStrategy
- The GlideExecutor.UncaughtThrowableStrategy
to use to
handle uncaught exceptions.public static GlideExecutor newSourceExecutor(int threadCount, String name, GlideExecutor.UncaughtThrowableStrategy uncaughtThrowableStrategy)
GlideExecutor.UncaughtThrowableStrategy
.
Source executors allow network operations on their threads.
threadCount
- The number of threads.name
- The prefix for each thread name.uncaughtThrowableStrategy
- The GlideExecutor.UncaughtThrowableStrategy
to use to
handle uncaught exceptions.public static GlideExecutor newUnlimitedSourceExecutor()
KEEP_ALIVE_TIME_MS
keep alive
time, the SOURCE_UNLIMITED_EXECUTOR_NAME
thread name prefix, the
GlideExecutor.UncaughtThrowableStrategy.DEFAULT
uncaught throwable strategy, and the SynchronousQueue
since using default unbounded
blocking queue, for example, PriorityBlockingQueue
effectively won't create more than
corePoolSize
threads.
See
ThreadPoolExecutor documentation.
Source executors allow network operations on their threads.
public static GlideExecutor newAnimationExecutor()
public static GlideExecutor newAnimationExecutor(int threadCount, GlideExecutor.UncaughtThrowableStrategy uncaughtThrowableStrategy)
GlideExecutor.UncaughtThrowableStrategy
to use when loading frames of animations.@NonNull public Future<?> submit(@NonNull Runnable task)
submit
in interface ExecutorService
@NonNull public <T> List<Future<T>> invokeAll(@NonNull Collection<? extends Callable<T>> tasks) throws InterruptedException
invokeAll
in interface ExecutorService
InterruptedException
@NonNull public <T> List<Future<T>> invokeAll(@NonNull Collection<? extends Callable<T>> tasks, long timeout, @NonNull TimeUnit unit) throws InterruptedException
invokeAll
in interface ExecutorService
InterruptedException
@NonNull public <T> T invokeAny(@NonNull Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException
invokeAny
in interface ExecutorService
InterruptedException
ExecutionException
public <T> T invokeAny(@NonNull Collection<? extends Callable<T>> tasks, long timeout, @NonNull TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
invokeAny
in interface ExecutorService
InterruptedException
ExecutionException
TimeoutException
@NonNull public <T> Future<T> submit(@NonNull Runnable task, T result)
submit
in interface ExecutorService
public <T> Future<T> submit(@NonNull Callable<T> task)
submit
in interface ExecutorService
public void shutdown()
shutdown
in interface ExecutorService
@NonNull public List<Runnable> shutdownNow()
shutdownNow
in interface ExecutorService
public boolean isShutdown()
isShutdown
in interface ExecutorService
public boolean isTerminated()
isTerminated
in interface ExecutorService
public boolean awaitTermination(long timeout, @NonNull TimeUnit unit) throws InterruptedException
awaitTermination
in interface ExecutorService
InterruptedException
public static int calculateBestThreadCount()