Class DynamicConcurrent


  • public class DynamicConcurrent
    extends java.lang.Object
    Executor class to manage or submit the asynchronous works.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      java.util.concurrent.ExecutorService SERIAL_EXECUTOR
      An ExecutorService that executes tasks one at a time in serial order.
      java.util.concurrent.ExecutorService THREAD_POOL_EXECUTOR
      An ExecutorService that 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 a Runnable task 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 a Runnable task on the supplied executor service and perform operations with the handler and callback.
      void execute​(java.lang.Runnable runnable)
      Executes a Runnable on the default executor service.
      void execute​(java.util.concurrent.ExecutorService executorService, java.lang.Runnable runnable)
      Executes a Runnable for the supplied executor service.
      static java.util.concurrent.ExecutorService getDefaultExecutor()
      Returns the default executor service.
      static DynamicConcurrent getInstance()
      Retrieves the singleton instance of DynamicConcurrent.
      java.util.concurrent.ExecutorService getSerialExecutor()
      Returns the serial executor service.
      java.util.concurrent.ExecutorService getThreadPoolExecutor()
      Returns the thread pool executor service.
      <T,​V>
      java.util.concurrent.Future<?>
      submit​(java.util.concurrent.ExecutorService executorService, T task, V result)
      Submits a Runnable or Callable task on the supplied executor service and returns a Future representing that task.
      <T> java.util.concurrent.Future<?> submit​(T task)
      Submits a Runnable or Callable task on the default executor service and returns a Future representing that task.
      <T,​V>
      java.util.concurrent.Future<?>
      submit​(T task, V result)
      Submits a Runnable or Callable task on the default executor service and returns a Future representing that task.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • SERIAL_EXECUTOR

        public final java.util.concurrent.ExecutorService SERIAL_EXECUTOR
        An ExecutorService that 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
        An ExecutorService that can be used to execute tasks in parallel.
    • Method Detail

      • 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 a Runnable 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:
        Executor.execute(Runnable)
      • execute

        public void execute​(@Nullable
                            java.lang.Runnable runnable)
        Executes a Runnable on 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 a Runnable or Callable task on the supplied executor service and returns a Future 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:
        ExecutorService.submit(Runnable), ExecutorService.submit(Callable)
      • submit

        @Nullable
        public <T,​V> java.util.concurrent.Future<?> submit​(@Nullable
                                                                 T task,
                                                                 @Nullable
                                                                 V result)
        Submits a Runnable or Callable task on the default executor service and returns a Future 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:
        THREAD_POOL_EXECUTOR, ExecutorService.submit(Runnable), ExecutorService.submit(Callable)
      • submit

        @Nullable
        public <T> java.util.concurrent.Future<?> submit​(@Nullable
                                                         T task)
        Submits a Runnable or Callable task on the default executor service and returns a Future 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:
        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 a Runnable task 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 Future representing 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 a Runnable task 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 Future representing the pending completion of the task.
        See Also:
        THREAD_POOL_EXECUTOR