优化编排方式

This commit is contained in:
wuweifeng10 2020-02-25 16:28:15 +08:00
parent fe62735389
commit 7f46c40864
2 changed files with 60 additions and 3 deletions

View File

@ -542,9 +542,11 @@ public class WorkerWrapper<T, V> {
}
if (nextWrappers != null) {
for (WorkerWrapper<?, ?> workerWrapper : nextWrappers) {
if (selfIsMustSet != null) {
workerWrapper.addDepend(wrapper, selfIsMustSet.contains(workerWrapper));
boolean must = false;
if (selfIsMustSet != null && selfIsMustSet.contains(workerWrapper)) {
must = true;
}
workerWrapper.addDepend(wrapper, must);
wrapper.addNext(workerWrapper);
}
}

View File

@ -25,11 +25,12 @@ public class TestPar {
// testMulti4();
// testMulti4Reverse();
// testMulti5();
testMulti5Reverse();
// testMulti5Reverse();
// testMulti6();
// testMulti7();
// testMulti8();
// testMulti9();
testMulti9Reverse();
}
/**
@ -811,4 +812,58 @@ public class TestPar {
Async.beginWork(6000, wrapperW, wrapperW1);
Async.shutDown();
}
/**
* w1 -> w2 -> w3
* --- last
* w
* w1和w并行w执行完后就执行last此时bc还没开始bc就不需要执行了
*/
private static void testMulti9Reverse() throws ExecutionException, InterruptedException {
ParWorker1 w1 = new ParWorker1();
//注意这里如果w1的执行时间比w长那么w2和w3肯定不走 如果w1和w执行时间一样长多运行几次会发现w2有时走有时不走
// w1.setSleepTime(1100);
ParWorker w = new ParWorker();
ParWorker2 w2 = new ParWorker2();
ParWorker3 w3 = new ParWorker3();
ParWorker4 w4 = new ParWorker4();
WorkerWrapper<String, String> wrapperW1 = new WorkerWrapper.Builder<String, String>()
.worker(w1)
.callback(w1)
.param("w1")
.build();
WorkerWrapper<String, String> wrapperW = new WorkerWrapper.Builder<String, String>()
.worker(w)
.callback(w)
.param("w")
.build();
WorkerWrapper<String, String> last = new WorkerWrapper.Builder<String, String>()
.worker(w1)
.callback(w1)
.param("last")
.depend(wrapperW)
.build();
WorkerWrapper<String, String> wrapperW2 = new WorkerWrapper.Builder<String, String>()
.worker(w2)
.callback(w2)
.param("w2")
.depend(wrapperW1)
.build();
WorkerWrapper<String, String> wrapperW3 = new WorkerWrapper.Builder<String, String>()
.worker(w3)
.callback(w3)
.param("w3")
.depend(wrapperW2)
.next(last, false)
.build();
Async.beginWork(6000, wrapperW, wrapperW1);
Async.shutDown();
}
}