Commit 18621ff6 authored by lihao's avatar lihao

update project structure

parent 7bd17f04
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
1. 引入依赖 1. 引入依赖
```xml ```xml
<groupId>com.mushiny</groupId> <groupId>com.mushiny</groupId>
<artifactId>task-executor-kit</artifactId> <artifactId>task-executor-kit</artifactId>
<version>1.0.0-RELEASE</version> <version>1.0.0-RELEASE</version>
``` ```
2. 获取任务执行实例 2. 获取任务执行实例
...@@ -18,23 +18,23 @@ ...@@ -18,23 +18,23 @@
3. 初始化执行器 3. 初始化执行器
```java ```java
executor.init( executor.init(
(data, context) -> { (data, context) -> {
data.setName(data.getName() + "handle"); data.setName(data.getName() + "handle");
try { try {
Thread.sleep(SLEEP_TIME); Thread.sleep(SLEEP_TIME);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
return "success"; return "success";
}, // 需要处理的业务逻辑 }, // 需要处理的业务逻辑
list, // 需要处理的业务数据列表 list, // 需要处理的业务数据列表
new User(30, "leehyoo") // 其他公用查询参数 new User(30, "leehyoo") // 其他公用查询参数
); );
``` ```
4. 获取查询结果 4. 获取查询结果
```java ```java
boolean result = executor.execute(); boolean result = executor.execute();
``` ```
# 注意事项 # 注意事项
......
...@@ -8,20 +8,27 @@ ...@@ -8,20 +8,27 @@
<version>1.0.0-RELEASE</version> <version>1.0.0-RELEASE</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>task-executor-kit</artifactId> <artifactId>task-executor-kit</artifactId>
<version>1.0.0-RELEASE</version>
<packaging>pom</packaging>
<modules>
<module>task-executor-core</module>
</modules>
<properties> <properties>
<maven.compiler.source>8</maven.compiler.source> <maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target> <maven.compiler.target>8</maven.compiler.target>
</properties> </properties>
<dependencies> <dependencyManagement>
<dependency> <dependencies>
<groupId>junit</groupId> <dependency>
<artifactId>junit</artifactId> <groupId>junit</groupId>
<version>4.13.2</version> <artifactId>junit</artifactId>
<scope>test</scope> <version>4.13.2</version>
</dependency> <scope>test</scope>
</dependencies> </dependency>
</dependencies>
</dependencyManagement>
</project> </project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>task-executor-kit</artifactId>
<groupId>com.mushiny</groupId>
<version>1.0.0-RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>task-executor-core</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.mushiny.task; package com.mushiny.task.executor.core;
import java.util.Collection; import java.util.Collection;
import java.util.function.BiFunction; import java.util.function.BiFunction;
......
package com.mushiny.task; package com.mushiny.task.executor.core;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.*; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Consumer; import java.util.function.Consumer;
......
package com.mushiny.task; package com.mushiny.task.executor.core;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
......
package com.mushiny.task; package com.mushiny.task.executor.core;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
...@@ -19,7 +20,7 @@ public class TaskTests { ...@@ -19,7 +20,7 @@ public class TaskTests {
@Before @Before
public void init() { public void init() {
list = new ArrayList<>(); list = new ArrayList<>();
for (int i = 0; i < 20; i++) { for (int i = 0; i < 200; i++) {
list.add(new User(i, "leehyoo" + i)); list.add(new User(i, "leehyoo" + i));
} }
} }
...@@ -42,26 +43,11 @@ public class TaskTests { ...@@ -42,26 +43,11 @@ public class TaskTests {
} }
@Test
public void normalLoopTest() {
User context = new User(30, "leehyoo");
list.forEach(data -> {
data.setName(data.getName() + "handle");
try {
Thread.sleep(SLEEP_TIME);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
}
@Test @Test
public void multiTaskLoopWithArgsTest() { public void multiTaskLoopWithArgsTest() {
TaskExecutor<User, User, String> executor = TaskPoolFactory.createExecutor(new ThreadPoolExecutor(5, 6, TaskExecutor<User, User, String> executor = TaskPoolFactory.createExecutor(new ThreadPoolExecutor(8, 9,
0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>())); 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>()), 60L, TimeUnit.SECONDS);
executor.init((data, context) -> { executor.init((data, context) -> {
data.setName(data.getName() + "handle"); data.setName(data.getName() + "handle");
...@@ -103,7 +89,7 @@ public class TaskTests { ...@@ -103,7 +89,7 @@ public class TaskTests {
@Test @Test
public void errorRecordCallbackTest() { public void errorRecordCallbackTest() {
TaskExecutor<User, User, String> executor = TaskPoolFactory.createExecutor(); TaskExecutor<User, User, String> executor = TaskPoolFactory.createExecutor();
List<User> errors = new ArrayList<>(); List<User> errors = Collections.synchronizedList(new ArrayList<>());
executor.init((data, context) -> { executor.init((data, context) -> {
data.setName(data.getName() + "handle"); data.setName(data.getName() + "handle");
try { try {
...@@ -122,4 +108,18 @@ public class TaskTests { ...@@ -122,4 +108,18 @@ public class TaskTests {
Assert.assertFalse(result); Assert.assertFalse(result);
} }
@Test
public void normalLoopTest() {
User context = new User(30, "leehyoo");
list.forEach(data -> {
data.setName(data.getName() + "handle");
try {
Thread.sleep(SLEEP_TIME);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
}
} }
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