Commit 18621ff6 authored by lihao's avatar lihao

update project structure

parent 7bd17f04
...@@ -8,14 +8,19 @@ ...@@ -8,14 +8,19 @@
<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>
<dependencyManagement>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
...@@ -24,4 +29,6 @@ ...@@ -24,4 +29,6 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </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