Class TaskExecutor

  • All Implemented Interfaces:
    java.util.concurrent.Executor, java.util.concurrent.ExecutorService

    public final class TaskExecutor
    extends java.util.concurrent.ThreadPoolExecutor
    Executor for tasks that guarantee that only one instance with the same identifier will be run
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.concurrent.ThreadPoolExecutor

        java.util.concurrent.ThreadPoolExecutor.AbortPolicy, java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy, java.util.concurrent.ThreadPoolExecutor.DiscardOldestPolicy, java.util.concurrent.ThreadPoolExecutor.DiscardPolicy
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String INTENT_WORK_FINISHED
      Intent action when work is over
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected TaskExecutor​(android.content.Context context, int corePoolSize, int maximumPoolSize, long keepAliveTime, java.util.concurrent.TimeUnit unit, java.util.concurrent.BlockingQueue<java.lang.Runnable> workQueue)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void afterExecute​(java.lang.Runnable r, java.lang.Throwable t)  
      void execute​(java.lang.Runnable command)  
      boolean isBusy()
      Is the task executor currently busy at running tasks
      static TaskExecutor provide​(android.content.Context context)  
      java.util.concurrent.Future<?> submit​(TaskRunnable task)
      Submit a new task to the executor.
      If a task with the same identifier is running, it will be cancel
      If a task with the same identifier is in queue, it will be removed.
      • Methods inherited from class java.util.concurrent.ThreadPoolExecutor

        allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, beforeExecute, finalize, getActiveCount, getCompletedTaskCount, getCorePoolSize, getKeepAliveTime, getLargestPoolSize, getMaximumPoolSize, getPoolSize, getQueue, getRejectedExecutionHandler, getTaskCount, getThreadFactory, isShutdown, isTerminated, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setCorePoolSize, setKeepAliveTime, setMaximumPoolSize, setRejectedExecutionHandler, setThreadFactory, shutdown, shutdownNow, terminated, toString
      • Methods inherited from class java.util.concurrent.AbstractExecutorService

        invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submit
      • Methods inherited from class java.lang.Object

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

      • INTENT_WORK_FINISHED

        public static final java.lang.String INTENT_WORK_FINISHED
        Intent action when work is over
        See Also:
        Constant Field Values
    • Constructor Detail

      • TaskExecutor

        protected TaskExecutor​(android.content.Context context,
                               int corePoolSize,
                               int maximumPoolSize,
                               long keepAliveTime,
                               java.util.concurrent.TimeUnit unit,
                               java.util.concurrent.BlockingQueue<java.lang.Runnable> workQueue)
        Parameters:
        corePoolSize -
        maximumPoolSize -
        keepAliveTime -
        unit -
        workQueue -
    • Method Detail

      • provide

        public static TaskExecutor provide​(android.content.Context context)
      • submit

        public java.util.concurrent.Future<?> submit​(TaskRunnable task)
        Submit a new task to the executor.
        If a task with the same identifier is running, it will be cancel
        If a task with the same identifier is in queue, it will be removed.
        Parameters:
        task -
        Returns:
      • isBusy

        public boolean isBusy()
        Is the task executor currently busy at running tasks
        Returns:
        true is working, false otherwise
      • execute

        public void execute​(java.lang.Runnable command)
        Specified by:
        execute in interface java.util.concurrent.Executor
        Overrides:
        execute in class java.util.concurrent.ThreadPoolExecutor
      • afterExecute

        protected void afterExecute​(java.lang.Runnable r,
                                    java.lang.Throwable t)
        Overrides:
        afterExecute in class java.util.concurrent.ThreadPoolExecutor