public class ExecutorDispatcher extends Object implements Task.Dispatcher, ThreadFactory, RejectedExecutionHandler
Worker dispatcher with an ExecutorService. Note that if the executor's work
queue is bounded, the excessive task will be added to the pending waiting for a working
task to be finished.
Use attach(ExecutorService) to set an existing executor, but if you do not use embed
executor, you have to deal with the bounded issue.
Use attach(Handler) to set an existing handler, which is used to schedule task
with the executor.
TAG| 构造器和说明 |
|---|
ExecutorDispatcher(int threadPoolSize) |
ExecutorDispatcher(int threadPoolSize,
int capacity) |
| 限定符和类型 | 方法和说明 |
|---|---|
ExecutorDispatcher |
attach(ExecutorService executor)
Attach an existing
ExecutorService to dispatcher, so that we don't need to create
an new one. |
ExecutorDispatcher |
attach(android.os.Handler scheduler)
Attach an existing scheduler to dispatcher, so that we don't need to create an new one.
|
void |
finish(Runnable runnable)
When a task is finished, it will call this method.
|
ExecutorService |
getExecutor() |
boolean |
has(int what)
Check if there exists the task with the specific id.
|
boolean |
has(Runnable runnable)
Check if there exists the task with the specific runnable.
|
boolean |
isRunning()
Whether or not the dispatcher is working.
|
Thread |
newThread(Runnable r) |
void |
post(int what,
Runnable runnable)
Add an task to the dispatcher with id.
|
void |
post(Runnable runnable)
Add an task to the dispatcher.
|
void |
postDelay(int what,
Runnable runnable,
long millis)
Schedule an task to the dispatcher with id.
|
void |
postDelay(Runnable runnable,
long millis)
Schedule an task to the dispatcher.
|
void |
rejectedExecution(Runnable r,
ThreadPoolExecutor executor) |
void |
shutdown()
Terminate the dispatcher.
|
void |
start()
Start the dispatcher before it can work.
|
public ExecutorDispatcher(int threadPoolSize)
public ExecutorDispatcher(int threadPoolSize,
int capacity)
public ExecutorDispatcher attach(android.os.Handler scheduler)
Task.Dispatcherattach 在接口中 Task.Dispatcherpublic ExecutorDispatcher attach(ExecutorService executor)
ExecutorService to dispatcher, so that we don't need to create
an new one.public ExecutorService getExecutor()
public void start()
Task.Dispatcherstart 在接口中 Task.Dispatcherpublic boolean isRunning()
Task.DispatcherisRunning 在接口中 Task.Dispatcherpublic void post(Runnable runnable)
Task.Dispatcherpost 在接口中 Task.Dispatcherpublic void post(int what,
Runnable runnable)
Task.Dispatcherpost 在接口中 Task.Dispatcherpublic void postDelay(Runnable runnable, long millis)
Task.DispatcherpostDelay 在接口中 Task.Dispatcherpublic void postDelay(int what,
Runnable runnable,
long millis)
Task.DispatcherpostDelay 在接口中 Task.Dispatcherpublic boolean has(int what)
Task.Dispatcherhas 在接口中 Task.Dispatcherpublic boolean has(Runnable runnable)
Task.Dispatcherhas 在接口中 Task.Dispatcherpublic void finish(Runnable runnable)
Task.Dispatcherfinish 在接口中 Task.Dispatcherpublic void shutdown()
Task.Dispatchershutdown 在接口中 Task.Dispatcherpublic Thread newThread(Runnable r)
newThread 在接口中 ThreadFactorypublic void rejectedExecution(Runnable r, ThreadPoolExecutor executor)
rejectedExecution 在接口中 RejectedExecutionHandler