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 class |
GlideExecutor.Builder
A builder for
GlideExecutor s. |
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,
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.Builder |
newAnimationBuilder()
Returns a new fixed 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()
Shortcut for calling
GlideExecutor.Builder.build() on newAnimationBuilder() . |
static GlideExecutor |
newAnimationExecutor(int threadCount,
GlideExecutor.UncaughtThrowableStrategy uncaughtThrowableStrategy)
Deprecated.
Use
newAnimationBuilder() instead. |
static GlideExecutor.Builder |
newDiskCacheBuilder()
Returns a new
GlideExecutor.Builder with the DEFAULT_DISK_CACHE_EXECUTOR_THREADS threads,
DEFAULT_DISK_CACHE_EXECUTOR_NAME name and GlideExecutor.UncaughtThrowableStrategy.DEFAULT
uncaught throwable strategy. |
static GlideExecutor |
newDiskCacheExecutor()
Shortcut for calling
GlideExecutor.Builder.build() on newDiskCacheBuilder() . |
static GlideExecutor |
newDiskCacheExecutor(GlideExecutor.UncaughtThrowableStrategy uncaughtThrowableStrategy)
Deprecated.
Use
newDiskCacheBuilder() and Builder#setUncaughtThrowableStrategy(UncaughtThrowableStrategy) instead. |
static GlideExecutor |
newDiskCacheExecutor(int threadCount,
java.lang.String name,
GlideExecutor.UncaughtThrowableStrategy uncaughtThrowableStrategy)
Deprecated.
Use
newDiskCacheBuilder() instead. |
static GlideExecutor.Builder |
newSourceBuilder()
Returns a new
GlideExecutor.Builder 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()
Shortcut for calling
GlideExecutor.Builder.build() on newSourceBuilder() . |
static GlideExecutor |
newSourceExecutor(GlideExecutor.UncaughtThrowableStrategy uncaughtThrowableStrategy)
Deprecated.
Use
newSourceBuilder() instead. |
static GlideExecutor |
newSourceExecutor(int threadCount,
java.lang.String name,
GlideExecutor.UncaughtThrowableStrategy uncaughtThrowableStrategy)
Deprecated.
Use
newSourceBuilder() instead. |
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.Builder newDiskCacheBuilder()
GlideExecutor.Builder
with the DEFAULT_DISK_CACHE_EXECUTOR_THREADS
threads,
DEFAULT_DISK_CACHE_EXECUTOR_NAME
name and GlideExecutor.UncaughtThrowableStrategy.DEFAULT
uncaught throwable strategy.
Disk cache executors do not allow network operations on their threads.
public static GlideExecutor newDiskCacheExecutor()
GlideExecutor.Builder.build()
on newDiskCacheBuilder()
.@Deprecated public static GlideExecutor newDiskCacheExecutor(GlideExecutor.UncaughtThrowableStrategy uncaughtThrowableStrategy)
newDiskCacheBuilder()
and Builder#setUncaughtThrowableStrategy(UncaughtThrowableStrategy)
instead.@Deprecated public static GlideExecutor newDiskCacheExecutor(int threadCount, java.lang.String name, GlideExecutor.UncaughtThrowableStrategy uncaughtThrowableStrategy)
newDiskCacheBuilder()
instead.public static GlideExecutor.Builder newSourceBuilder()
GlideExecutor.Builder
with the default thread count returned from 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.Builder.build()
on newSourceBuilder()
.@Deprecated public static GlideExecutor newSourceExecutor(GlideExecutor.UncaughtThrowableStrategy uncaughtThrowableStrategy)
newSourceBuilder()
instead.@Deprecated public static GlideExecutor newSourceExecutor(int threadCount, java.lang.String name, GlideExecutor.UncaughtThrowableStrategy uncaughtThrowableStrategy)
newSourceBuilder()
instead.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.Builder newAnimationBuilder()
Animation executors do not allow network operations on their threads.
public static GlideExecutor newAnimationExecutor()
GlideExecutor.Builder.build()
on newAnimationBuilder()
.@Deprecated public static GlideExecutor newAnimationExecutor(int threadCount, GlideExecutor.UncaughtThrowableStrategy uncaughtThrowableStrategy)
newAnimationBuilder()
instead.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.ExecutorService
java.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.ExecutorService
java.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.ExecutorService
java.lang.InterruptedException
java.util.concurrent.ExecutionException
public <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.ExecutorService
java.lang.InterruptedException
java.util.concurrent.ExecutionException
java.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.ExecutorService
public <T> java.util.concurrent.Future<T> submit(@NonNull java.util.concurrent.Callable<T> task)
submit
in interface java.util.concurrent.ExecutorService
public void shutdown()
shutdown
in interface java.util.concurrent.ExecutorService
@NonNull public java.util.List<java.lang.Runnable> shutdownNow()
shutdownNow
in interface java.util.concurrent.ExecutorService
public boolean isShutdown()
isShutdown
in interface java.util.concurrent.ExecutorService
public boolean isTerminated()
isTerminated
in interface java.util.concurrent.ExecutorService
public boolean awaitTermination(long timeout, @NonNull java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
awaitTermination
in interface java.util.concurrent.ExecutorService
java.lang.InterruptedException
public java.lang.String toString()
toString
in class java.lang.Object
public static int calculateBestThreadCount()