fix:最后一个任务不能执行的问题

This commit is contained in:
kyle
2022-03-18 16:20:45 +08:00
parent 3b5a50c5bb
commit db3a162d1a
4 changed files with 10 additions and 6 deletions

View File

@@ -362,7 +362,9 @@ 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);
//FIXME 等待200毫秒重新投入线程池主要为了调起最后一个任务
Thread.sleep(200L);
executorService.submit(() -> this.work(executorService, fromWrapper, remainTime, group));
return;
case FAST_FAIL:
if (setState(state, STARTED, ERROR)) {

View File

@@ -1,6 +1,5 @@
package com.jd.platform.async.wrapper.strategy.depend;
import com.jd.platform.async.exception.SkippedException;
import com.jd.platform.async.worker.ResultState;
import com.jd.platform.async.worker.WorkResult;
import com.jd.platform.async.wrapper.WorkerWrapper;
@@ -111,7 +110,6 @@ 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

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

View File

@@ -315,6 +315,7 @@ public class HashedWheelTimer extends AbstractWheelTimer {
startTimeInitialized.countDown();
do {
//TODO 时间轮这里结束不了任务
final long deadline = waitForNextTick();
if (deadline > 0) {
int idx = (int) (tick & mask);