Commit 7bd17f04 authored by lihao's avatar lihao

fix CountDownLatch is null when await time out

parent 57fe5d13
......@@ -2,13 +2,21 @@
多线程处理列表逻辑
# 使用方式
1. 获取任务执行实例
1. 引入依赖
```xml
<groupId>com.mushiny</groupId>
<artifactId>task-executor-kit</artifactId>
<version>1.0.0-RELEASE</version>
```
2. 获取任务执行实例
```java
TaskExecutor<User, User, String> executor = TaskPoolFactory.createExecutor();
```
2. 初始化执行器
3. 初始化执行器
```java
executor.init(
(data, context) -> {
......@@ -24,7 +32,7 @@
new User(30, "leehyoo") // 其他公用查询参数
);
```
3. 获取查询结果
4. 获取查询结果
```java
boolean result = executor.execute();
```
......
......@@ -71,11 +71,15 @@ public class TaskExecutor<T, U, R> {
}
failCount.addAndGet(1);
} finally {
countDownLatch.countDown();
// await超时会导致,loop里面继续执行,但是已经执行destroy方法将latch对象销毁
if (Objects.nonNull(countDownLatch)) {
countDownLatch.countDown();
}
}
}));
try {
return countDownLatch.await(countDownTimeOut, timeUnit) && failCount.get() <= 0;
return countDownLatch.await(countDownTimeOut, timeUnit)
&& failCount.get() <= 0;
} catch (InterruptedException e) {
return false;
} finally {
......
......@@ -12,7 +12,7 @@ import java.util.concurrent.TimeUnit;
public class TaskTests {
private int SLEEP_TIME = 100;
private int SLEEP_TIME = 1000;
private List<User> list;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment