public final class GlideExecutor
extends java.lang.Object
implements java.util.concurrent.ExecutorService
ThreadPoolExecutor for running jobs in Glide.| Modifier and Type | Class and Description |
|---|---|
static interface |
GlideExecutor.UncaughtThrowableStrategy
A strategy for handling unexpected and uncaught
Throwables thrown by futures run on the
pool. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
awaitTermination(long timeout,
java.util.concurrent.TimeUnit unit) |
static int |
calculateBestThreadCount()
Determines the number of cores available on the device.
|
void |
execute(java.lang.Runnable command) |
<T> java.util.List<java.util.concurrent.Future<T>> |
invokeAll(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks) |
<T> java.util.List<java.util.concurrent.Future<T>> |
invokeAll(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks,
long timeout,
java.util.concurrent.TimeUnit unit) |
<T> T |
invokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks) |
<T> T |
invokeAny(java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks,
long timeout,
java.util.concurrent.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,
java.lang.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,
java.lang.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() |
java.util.List<java.lang.Runnable> |
shutdownNow() |
<T> java.util.concurrent.Future<T> |
submit(java.util.concurrent.Callable<T> task) |
java.util.concurrent.Future<?> |
submit(java.lang.Runnable task) |
<T> java.util.concurrent.Future<T> |
submit(java.lang.Runnable task,
T result) |
java.lang.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, java.lang.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, java.lang.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.public void execute(@NonNull
java.lang.Runnable command)
execute in interface java.util.concurrent.Executor@NonNull
public java.util.concurrent.Future<?> submit(@NonNull
java.lang.Runnable task)
submit in interface java.util.concurrent.ExecutorService@NonNull
public <T> java.util.List<java.util.concurrent.Future<T>> invokeAll(@NonNull
java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)
throws java.lang.InterruptedException
invokeAll in interface java.util.concurrent.ExecutorServicejava.lang.InterruptedException@NonNull
public <T> java.util.List<java.util.concurrent.Future<T>> invokeAll(@NonNull
java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks,
long timeout,
@NonNull
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException
invokeAll in interface java.util.concurrent.ExecutorServicejava.lang.InterruptedException@NonNull
public <T> T invokeAny(@NonNull
java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks)
throws java.lang.InterruptedException,
java.util.concurrent.ExecutionException
invokeAny in interface java.util.concurrent.ExecutorServicejava.lang.InterruptedExceptionjava.util.concurrent.ExecutionExceptionpublic <T> T invokeAny(@NonNull
java.util.Collection<? extends java.util.concurrent.Callable<T>> tasks,
long timeout,
@NonNull
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException,
java.util.concurrent.ExecutionException,
java.util.concurrent.TimeoutException
invokeAny in interface java.util.concurrent.ExecutorServicejava.lang.InterruptedExceptionjava.util.concurrent.ExecutionExceptionjava.util.concurrent.TimeoutException@NonNull
public <T> java.util.concurrent.Future<T> submit(@NonNull
java.lang.Runnable task,
T result)
submit in interface java.util.concurrent.ExecutorServicepublic <T> java.util.concurrent.Future<T> submit(@NonNull
java.util.concurrent.Callable<T> task)
submit in interface java.util.concurrent.ExecutorServicepublic void shutdown()
shutdown in interface java.util.concurrent.ExecutorService@NonNull public java.util.List<java.lang.Runnable> shutdownNow()
shutdownNow in interface java.util.concurrent.ExecutorServicepublic boolean isShutdown()
isShutdown in interface java.util.concurrent.ExecutorServicepublic boolean isTerminated()
isTerminated in interface java.util.concurrent.ExecutorServicepublic boolean awaitTermination(long timeout,
@NonNull
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException
awaitTermination in interface java.util.concurrent.ExecutorServicejava.lang.InterruptedExceptionpublic java.lang.String toString()
toString in class java.lang.Objectpublic static int calculateBestThreadCount()