Class DynamicConcurrent
java.lang.Object
com.pranavpandey.android.dynamic.util.concurrent.DynamicConcurrent
Executor class to manage or submit the asynchronous works.
-
Field Summary
Modifier and TypeFieldDescriptionfinal ExecutorService
AnExecutorService
that executes tasks one at a time in serial order.final ExecutorService
AnExecutorService
that can be used to execute tasks in parallel. -
Method Summary
Modifier and TypeMethodDescription<V,
P, R> Future<?> async
(Handler handler, DynamicCallback<V, P, R> callback) Submits aRunnable
task on the default executor service and perform operations with the handler and callback.<V,
P, R> Future<?> async
(ExecutorService executorService, Handler handler, DynamicCallback<V, P, R> callback) Submits aRunnable
task on the supplied executor service and perform operations with the handler and callback.void
Executes aRunnable
on the default executor service.void
execute
(ExecutorService executorService, Runnable runnable) Executes aRunnable
for the supplied executor service.static ExecutorService
Returns the default executor service.static DynamicConcurrent
Retrieves the singleton instance ofDynamicConcurrent
.Returns the serial executor service.Returns the thread pool executor service.<T,
V> Future<?> submit
(ExecutorService executorService, T task, V result) <T> Future<?>
submit
(T task) <T,
V> Future<?> submit
(T task, V result)
-
Field Details
-
SERIAL_EXECUTOR
AnExecutorService
that executes tasks one at a time in serial order. This serialization is global to a particular process. -
THREAD_POOL_EXECUTOR
AnExecutorService
that can be used to execute tasks in parallel.
-
-
Method Details
-
getInstance
Retrieves the singleton instance ofDynamicConcurrent
.Must be called before accessing the public methods.
- Returns:
- The singleton instance of
DynamicConcurrent
-
getDefaultExecutor
Returns the default executor service.- Returns:
- The default executor service.
-
getSerialExecutor
Returns the serial executor service.- Returns:
- The serial executor service.
-
getThreadPoolExecutor
Returns the thread pool executor service.- Returns:
- The thread pool executor service.
-
execute
Executes aRunnable
for the supplied executor service.Otherwise, use the default executor service.
- Parameters:
executorService
- The executor service to be used.runnable
- The task to be executed.- See Also:
-
execute
Executes aRunnable
on the default executor service.- Parameters:
runnable
- The task to be executed.- See Also:
-
submit
@Nullable public <T,V> Future<?> submit(@Nullable ExecutorService executorService, @Nullable T task, @Nullable V result) Submits aRunnable
orCallable
task on the supplied executor service and returns aFuture
representing that task.- Type Parameters:
T
- The type of the task.V
- The type of the result.- Parameters:
executorService
- The executor service to be used.task
- The task to be submitted.result
- The result to return.- Returns:
- The
Future
representing the pending completion of the task. - See Also:
-
submit
Submits aRunnable
orCallable
task on the default executor service and returns aFuture
representing that task.- Type Parameters:
T
- The type of the task.V
- The type of the result.- Parameters:
task
- The task to be submitted.result
- The result to return.- Returns:
- The
Future
representing the pending completion of the task. - See Also:
-
submit
Submits aRunnable
orCallable
task on the default executor service and returns aFuture
representing that task.- Type Parameters:
T
- The type of the task.- Parameters:
task
- The task to be submitted.- Returns:
- The
Future
representing the pending completion of the task. - See Also:
-