Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
PubTools-tools
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liuxingyu
PubTools-tools
Commits
7bd17f04
Commit
7bd17f04
authored
Aug 15, 2023
by
lihao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix CountDownLatch is null when await time out
parent
57fe5d13
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
5 deletions
+17
-5
README.md
task-executor-kit/README.md
+11
-3
TaskExecutor.java
...utor-kit/src/main/java/com/mushiny/task/TaskExecutor.java
+5
-1
TaskTests.java
...xecutor-kit/src/test/java/com/mushiny/task/TaskTests.java
+1
-1
No files found.
task-executor-kit/README.md
View file @
7bd17f04
...
@@ -2,13 +2,21 @@
...
@@ -2,13 +2,21 @@
多线程处理列表逻辑
多线程处理列表逻辑
# 使用方式
# 使用方式
1.
获取任务执行实例
1.
引入依赖
```xml
<groupId>com.mushiny</groupId>
<artifactId>task-executor-kit</artifactId>
<version>1.0.0-RELEASE</version>
```
2.
获取任务执行实例
```java
```java
TaskExecutor<User, User, String> executor = TaskPoolFactory.createExecutor();
TaskExecutor<User, User, String> executor = TaskPoolFactory.createExecutor();
```
```
2
.
初始化执行器
3
.
初始化执行器
```java
```java
executor.init(
executor.init(
(data, context) -> {
(data, context) -> {
...
@@ -24,7 +32,7 @@
...
@@ -24,7 +32,7 @@
new User(30, "leehyoo") // 其他公用查询参数
new User(30, "leehyoo") // 其他公用查询参数
);
);
```
```
3
.
获取查询结果
4
.
获取查询结果
```java
```java
boolean result = executor.execute();
boolean result = executor.execute();
```
```
...
...
task-executor-kit/src/main/java/com/mushiny/task/TaskExecutor.java
View file @
7bd17f04
...
@@ -71,11 +71,15 @@ public class TaskExecutor<T, U, R> {
...
@@ -71,11 +71,15 @@ public class TaskExecutor<T, U, R> {
}
}
failCount
.
addAndGet
(
1
);
failCount
.
addAndGet
(
1
);
}
finally
{
}
finally
{
// await超时会导致,loop里面继续执行,但是已经执行destroy方法将latch对象销毁
if
(
Objects
.
nonNull
(
countDownLatch
))
{
countDownLatch
.
countDown
();
countDownLatch
.
countDown
();
}
}
}
}));
}));
try
{
try
{
return
countDownLatch
.
await
(
countDownTimeOut
,
timeUnit
)
&&
failCount
.
get
()
<=
0
;
return
countDownLatch
.
await
(
countDownTimeOut
,
timeUnit
)
&&
failCount
.
get
()
<=
0
;
}
catch
(
InterruptedException
e
)
{
}
catch
(
InterruptedException
e
)
{
return
false
;
return
false
;
}
finally
{
}
finally
{
...
...
task-executor-kit/src/test/java/com/mushiny/task/TaskTests.java
View file @
7bd17f04
...
@@ -12,7 +12,7 @@ import java.util.concurrent.TimeUnit;
...
@@ -12,7 +12,7 @@ import java.util.concurrent.TimeUnit;
public
class
TaskTests
{
public
class
TaskTests
{
private
int
SLEEP_TIME
=
100
;
private
int
SLEEP_TIME
=
100
0
;
private
List
<
User
>
list
;
private
List
<
User
>
list
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment