Class DynamicConcurrent
- java.lang.Object
-
- com.pranavpandey.android.dynamic.util.concurrent.DynamicConcurrent
-
public class DynamicConcurrent extends java.lang.ObjectExecutor class to manage or submit the asynchronous works.
-
-
Field Summary
Fields Modifier and Type Field Description java.util.concurrent.ExecutorServiceSERIAL_EXECUTORAnExecutorServicethat executes tasks one at a time in serial order.java.util.concurrent.ExecutorServiceTHREAD_POOL_EXECUTORAnExecutorServicethat can be used to execute tasks in parallel.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <V,P,R>
java.util.concurrent.Future<?>async(android.os.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>
java.util.concurrent.Future<?>async(java.util.concurrent.ExecutorService executorService, android.os.Handler handler, DynamicCallback<V,P,R> callback)Submits aRunnabletask on the supplied executor service and perform operations with the handler and callback.voidexecute(java.lang.Runnable runnable)Executes aRunnableon the default executor service.voidexecute(java.util.concurrent.ExecutorService executorService, java.lang.Runnable runnable)Executes aRunnablefor the supplied executor service.static java.util.concurrent.ExecutorServicegetDefaultExecutor()Returns the default executor service.static DynamicConcurrentgetInstance()Retrieves the singleton instance ofDynamicConcurrent.java.util.concurrent.ExecutorServicegetSerialExecutor()Returns the serial executor service.java.util.concurrent.ExecutorServicegetThreadPoolExecutor()Returns the thread pool executor service.<T,V>
java.util.concurrent.Future<?>submit(java.util.concurrent.ExecutorService executorService, T task, V result)Submits aRunnableorCallabletask on the supplied executor service and returns aFuturerepresenting that task.<T> java.util.concurrent.Future<?>submit(T task)Submits aRunnableorCallabletask on the default executor service and returns aFuturerepresenting that task.<T,V>
java.util.concurrent.Future<?>submit(T task, V result)Submits aRunnableorCallabletask on the default executor service and returns aFuturerepresenting that task.
-
-
-
Field Detail
-
SERIAL_EXECUTOR
public final java.util.concurrent.ExecutorService SERIAL_EXECUTOR
AnExecutorServicethat executes tasks one at a time in serial order. This serialization is global to a particular process.
-
THREAD_POOL_EXECUTOR
public final java.util.concurrent.ExecutorService THREAD_POOL_EXECUTOR
AnExecutorServicethat can be used to execute tasks in parallel.
-
-
Method Detail
-
getInstance
@NonNull public static DynamicConcurrent getInstance()
Retrieves the singleton instance ofDynamicConcurrent.Must be called before accessing the public methods.
- Returns:
- The singleton instance of
DynamicConcurrent
-
getDefaultExecutor
@NonNull public static java.util.concurrent.ExecutorService getDefaultExecutor()
Returns the default executor service.- Returns:
- The default executor service.
-
getSerialExecutor
@NonNull public java.util.concurrent.ExecutorService getSerialExecutor()
Returns the serial executor service.- Returns:
- The serial executor service.
-
getThreadPoolExecutor
@NonNull public java.util.concurrent.ExecutorService getThreadPoolExecutor()
Returns the thread pool executor service.- Returns:
- The thread pool executor service.
-
execute
public void execute(@Nullable java.util.concurrent.ExecutorService executorService, @Nullable java.lang.Runnable runnable)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:
Executor.execute(Runnable)
-
execute
public void execute(@Nullable java.lang.Runnable runnable)Executes aRunnableon the default executor service.- Parameters:
runnable- The task to be executed.- See Also:
THREAD_POOL_EXECUTOR,Executor.execute(Runnable)
-
submit
@Nullable public <T,V> java.util.concurrent.Future<?> submit(@Nullable java.util.concurrent.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:
ExecutorService.submit(Runnable),ExecutorService.submit(Callable)
-
submit
@Nullable public <T,V> java.util.concurrent.Future<?> submit(@Nullable T task, @Nullable V result)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:
THREAD_POOL_EXECUTOR,ExecutorService.submit(Runnable),ExecutorService.submit(Callable)
-
submit
@Nullable public <T> java.util.concurrent.Future<?> submit(@Nullable T task)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:
THREAD_POOL_EXECUTOR,ExecutorService.submit(Runnable),ExecutorService.submit(Callable)
-
async
@Nullable public <V,P,R> java.util.concurrent.Future<?> async(@Nullable java.util.concurrent.ExecutorService executorService, @Nullable android.os.Handler handler, @Nullable DynamicCallback<V,P,R> callback)Submits aRunnabletask on the supplied executor service and perform operations with the handler and callback.- Type Parameters:
V- The type of the callback view.P- The type of the callback placeholder.R- The type of the callback result.- Parameters:
executorService- The executor service to be used.handler- The handler to be used.callback- The callback to be used.- Returns:
- The
Futurerepresenting the pending completion of the task.
-
async
@Nullable public <V,P,R> java.util.concurrent.Future<?> async(@Nullable android.os.Handler handler, @Nullable DynamicCallback<V,P,R> callback)Submits aRunnabletask on the default executor service and perform operations with the handler and callback.- Type Parameters:
V- The type of the callback view.P- The type of the callback placeholder.R- The type of the callback result.- Parameters:
handler- The handler to be used.callback- The callback to be used.- Returns:
- The
Futurerepresenting the pending completion of the task. - See Also:
THREAD_POOL_EXECUTOR
-
-