-
Notifications
You must be signed in to change notification settings - Fork 65
ParallelTask
Carlyle-Lee edited this page Jun 3, 2020
·
4 revisions
使用场景:将一个耗时的任务,并行化执行,加快任务执行的速度。
public ParallelTask setTimeOut(int timeOut)
Set how much time current thread is going to wait for other thread to join;
public ParallelTask addSubTask(Runnable run)
Add a sub task to run;
public ParallelTask addSubTask(Task task)
Add a sub task to run;
⚡ 重要
public void execute()
Run parallel tasks. Current thread will wait for all children tasks to finish until the setting time-out is reached. (if timeOut < 0 , it will wait until all tasks finished.)
执行全部之任务,子任务将会在子线程与当前线程中执行。此方法将会在全部子任务执行完成后或者设置的超时时间到达后才返回。
new ParalleTask()
.addSubTask(new Runnable() {
@Override
public void run() {
appendEventBusIndexStub0();
}
})
.addSubTask(new Runnable() {
@Override
public void run() {
appendEventBusIndexStub1();
}
})
.addSubTask(new Runnable() {
@Override
public void run() {
appendEventBusIndexStub2();
}
})
.addSubTask(new Runnable() {
@Override
public void run() {
appendEventBusIndexStub3();
}
})
.execute();