docs: ALL_DEPENDENCIES_ALL_SUCCESS算法上有缺陷

This commit is contained in:
kyle
2022-03-12 17:08:00 +08:00
parent f4721761e5
commit 3b5a50c5bb
4 changed files with 14 additions and 4 deletions

View File

@@ -1,4 +1,4 @@
如果只是需要用这个框架请往下看即可。如果需要深入了解这个框架是如何一步一步实现的从接到需求到每一步的思考每个类为什么这么设计为什么有这些方法也就是如何从0到1开发出这个框架作者在[csdn开了专栏](https://blog.csdn.net/tianyaleixiaowu/category_9637010.html)专门讲中间件如何从0开发包括并不限于这个小框架。京东内部同事可在cf上搜索erp也能看到。
如果只是需要用这个框架请往下看即可。如果需要深入了解这个框架是如何一步一步实现的从接到需求到每一步的思考每个类为什么这么设计为什么有这些方法也就是如何从0到1开发出这个框架作者在[csdn开了专栏](https://blog.csdn.net/tianyaleixiaowu/category_9637010.html) 专门讲中间件如何从0开发包括并不限于这个小框架。京东内部同事可在cf上搜索erp也能看到。
# 安装教程

View File

@@ -362,6 +362,7 @@ public abstract class WorkerWrapper<T, V> {
wrapperStrategy.judgeAction(getDependWrappers(), this, fromWrapper);
switch (judge.getDependenceAction()) {
case TAKE_REST:
System.out.println("TAKE_REST\t"+id+"\t"+fromWrapper.id);
return;
case FAST_FAIL:
if (setState(state, STARTED, ERROR)) {

View File

@@ -80,6 +80,14 @@ public interface DependenceStrategy {
* 被依赖的所有Wrapper都必须成功才能开始工作。
* 如果其中任一Wrapper还没有执行且不存在失败则休息。
* 如果其中任一Wrapper失败则立即失败。
*
* FIXME
* 这里有个问题,
* 假设任务A依赖B、C
*
* B执行时间比较长A-B的线程和A-C的线程都检测到B的res==nullDEFAULT
* 那么线程A就真的去休眠TAKE_REST而没有发起
* 导致整个任务长时间无法结束
*/
DependenceStrategy ALL_DEPENDENCIES_ALL_SUCCESS = new DependenceStrategy() {
@Override
@@ -103,6 +111,7 @@ public interface DependenceStrategy {
}
}
if (hasWaiting) {
System.out.println(Thread.currentThread().getName()+"\thasWaiting\t"+thisWrapper.getId()+"\t"+fromWrapper.getId());
return DependenceAction.TAKE_REST.emptyProperty();
}
return DependenceAction.START_WORK.emptyProperty();

View File

@@ -17,13 +17,13 @@ class Case1 {
.worker((param, allWrappers) -> {
System.out.println("wrapper(id=" + id + ") is working");
try {
if (!"F".equals(id)) {
if ("F".equals(id)) {
Thread.sleep(50);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
return null;
return id;
});
}
@@ -44,7 +44,7 @@ class Case1 {
)
.build();
try {
Async.work(1000, a, d).awaitFinish();
Async.work(10000, a, d).awaitFinish();
} catch (InterruptedException e) {
e.printStackTrace();
}