Class DynamicConcurrent
java.lang.Object
com.pranavpandey.android.dynamic.util.concurrent.DynamicConcurrent
Executor class to manage or submit the asynchronous works.
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal ExecutorServiceAnExecutorServicethat executes tasks one at a time in serial order.final ExecutorServiceAnExecutorServicethat 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 aRunnabletask 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 aRunnabletask on the supplied executor service and perform operations with the handler and callback.voidExecutes aRunnableon the default executor service.voidexecute(ExecutorService executorService, Runnable runnable) Executes aRunnablefor the supplied executor service.static ExecutorServiceReturns the default executor service.static DynamicConcurrentRetrieves 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
AnExecutorServicethat executes tasks one at a time in serial order. This serialization is global to a particular process. -
THREAD_POOL_EXECUTOR
AnExecutorServicethat 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 aRunnablefor 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 aRunnableon 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 aRunnableorCallabletask on the supplied executor service and returns aFuturerepresenting 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
Futurerepresenting the pending completion of the task. - See Also:
-
submit
Submits aRunnableorCallabletask on the default executor service and returns aFuturerepresenting 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
Futurerepresenting the pending completion of the task. - See Also:
-
submit
Submits aRunnableorCallabletask on the default executor service and returns aFuturerepresenting that task.- Type Parameters:
T- The type of the task.- Parameters:
task- The task to be submitted.- Returns:
- The
Futurerepresenting the pending completion of the task. - See Also:
-