Package com.batch.android.core
Class TaskExecutor
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- java.util.concurrent.ThreadPoolExecutor
-
- com.batch.android.core.TaskExecutor
-
- All Implemented Interfaces:
java.util.concurrent.Executor,java.util.concurrent.ExecutorService
public final class TaskExecutor extends java.util.concurrent.ThreadPoolExecutorExecutor 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.StringINTENT_WORK_FINISHEDIntent action when work is over
-
Constructor Summary
Constructors Modifier Constructor Description protectedTaskExecutor(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 voidafterExecute(java.lang.Runnable r, java.lang.Throwable t)voidexecute(java.lang.Runnable command)booleanisBusy()Is the task executor currently busy at running tasksstatic TaskExecutorprovide(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
-
-
-
-
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:
executein interfacejava.util.concurrent.Executor- Overrides:
executein classjava.util.concurrent.ThreadPoolExecutor
-
afterExecute
protected void afterExecute(java.lang.Runnable r, java.lang.Throwable t)- Overrides:
afterExecutein classjava.util.concurrent.ThreadPoolExecutor
-
-