public final class GlideExecutor extends ThreadPoolExecutor
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. |
ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicy
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_DISK_CACHE_EXECUTOR_NAME
The default thread name prefix for executors used to load/decode/transform data found in
Glide's cache.
|
static int |
DEFAULT_DISK_CACHE_EXECUTOR_THREADS
The default thread count for executors used to load/decode/transform data found in Glide's
cache.
|
static String |
DEFAULT_SOURCE_EXECUTOR_NAME
The default thread name prefix for executors used to load/decode/transform data not found in
cache.
|
Modifier and Type | Method and Description |
---|---|
static int |
calculateBestThreadCount()
Determines the number of cores available on the device.
|
void |
execute(Runnable command) |
static GlideExecutor |
newAnimationExecutor() |
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. |
<T> Future<T> |
submit(Callable<T> task) |
Future<?> |
submit(Runnable task) |
<T> Future<T> |
submit(Runnable task,
T result) |
afterExecute, allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, beforeExecute, finalize, getActiveCount, getCompletedTaskCount, getCorePoolSize, getKeepAliveTime, getLargestPoolSize, getMaximumPoolSize, getPoolSize, getQueue, getRejectedExecutionHandler, getTaskCount, getThreadFactory, isShutdown, isTerminated, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setCorePoolSize, setKeepAliveTime, setMaximumPoolSize, setRejectedExecutionHandler, setThreadFactory, shutdown, shutdownNow, terminated, toString
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor
public static final String DEFAULT_SOURCE_EXECUTOR_NAME
public static final String DEFAULT_DISK_CACHE_EXECUTOR_NAME
public static final int DEFAULT_DISK_CACHE_EXECUTOR_THREADS
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 void execute(Runnable command)
execute
in interface Executor
execute
in class ThreadPoolExecutor
@NonNull public Future<?> submit(Runnable task)
submit
in interface ExecutorService
submit
in class AbstractExecutorService
@NonNull public <T> Future<T> submit(Runnable task, T result)
submit
in interface ExecutorService
submit
in class AbstractExecutorService
public <T> Future<T> submit(Callable<T> task)
submit
in interface ExecutorService
submit
in class AbstractExecutorService
public static int calculateBestThreadCount()
Runtime.availableProcessors()
returns the number of awake cores, which may not
be the number of available cores depending on the device's current state. See
http://goo.gl/8H670N.