mirror of
https://gitee.com/jd-platform-opensource/asyncTool.git
synced 2025-12-26 05:37:19 +08:00
fix: 超时导致线程无法停止,因为最后一个任务的状态没有置为结束
This commit is contained in:
parent
efa4a9f46c
commit
a8e657e3ff
@ -20,6 +20,7 @@ import com.jd.platform.async.wrapper.strategy.skip.SkipStrategy;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.BiConsumer;
|
||||
@ -283,6 +284,11 @@ public abstract class WorkerWrapper<T, V> {
|
||||
if (setState(state, WORKING, AFTER_WORK)) {
|
||||
__function__callbackResultOfFalse_beginNext.accept(true);
|
||||
}
|
||||
}else {
|
||||
//如果任务超时,需要将最后那个超时任务设置为超时异常结束的
|
||||
if (setState(state, WORKING, ERROR)) {
|
||||
__function__fastFail_callbackResult$false_beginNext.accept(false, new TimeoutException());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (setState(state, WORKING, ERROR)) {
|
||||
@ -305,7 +311,6 @@ public abstract class WorkerWrapper<T, V> {
|
||||
// 总的已经超时了,就快速失败,进行下一个
|
||||
if (remainTime <= 0) {
|
||||
if (setState(state, states_of_beforeWorkingEnd, ERROR, null)) {
|
||||
System.out.println("快速失败");
|
||||
__function__fastFail_callbackResult$false_beginNext.accept(true, null);
|
||||
}
|
||||
return;
|
||||
|
||||
@ -21,7 +21,7 @@ class Case1 {
|
||||
try {
|
||||
if ("F".equals(id)) {
|
||||
System.out.println("wrapper(id=" + id + ") is working");
|
||||
Thread.sleep(100);
|
||||
Thread.sleep(2000);
|
||||
} else {
|
||||
System.out.println("wrapper(id=" + id + ") is worki444ng");
|
||||
}
|
||||
@ -63,7 +63,7 @@ class Case1 {
|
||||
)
|
||||
.build();
|
||||
try {
|
||||
Async.work(5000, a, d).awaitFinish();
|
||||
Async.work(1000, a, d).awaitFinish();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user