Commit 3b89d155 authored by lihao's avatar lihao

add logging

parent c914a370
...@@ -25,6 +25,12 @@ ...@@ -25,6 +25,12 @@
<version>4.13.2</version> <version>4.13.2</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.27</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
......
...@@ -21,5 +21,11 @@ ...@@ -21,5 +21,11 @@
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file
package com.mushiny.task.executor.core; package com.mushiny.task.executor.core;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collection; import java.util.Collection;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
...@@ -15,6 +18,9 @@ import java.util.function.Consumer; ...@@ -15,6 +18,9 @@ import java.util.function.Consumer;
*/ */
public class TaskExecutor<T, U, R> { public class TaskExecutor<T, U, R> {
private static final Logger log = LoggerFactory.getLogger(TaskExecutor.class);
/** /**
* 线程池 * 线程池
*/ */
...@@ -57,6 +63,9 @@ public class TaskExecutor<T, U, R> { ...@@ -57,6 +63,9 @@ public class TaskExecutor<T, U, R> {
* 执行函数 * 执行函数
*/ */
public boolean execute() { public boolean execute() {
if (log.isInfoEnabled()) {
log.info("task start ======");
}
TaskDefinition<T, U, R> t = this.task; TaskDefinition<T, U, R> t = this.task;
Collection<T> data = t.getData(); Collection<T> data = t.getData();
if (null == data || data.isEmpty()) { if (null == data || data.isEmpty()) {
...@@ -68,6 +77,9 @@ public class TaskExecutor<T, U, R> { ...@@ -68,6 +77,9 @@ public class TaskExecutor<T, U, R> {
data.forEach(d -> pool.execute(() -> { data.forEach(d -> pool.execute(() -> {
try { try {
Object apply = t.getHandler().apply(d, t.getContext()); Object apply = t.getHandler().apply(d, t.getContext());
if (log.isInfoEnabled()) {
log.info("sub task finish ======");
}
} catch (Exception ex) { } catch (Exception ex) {
if (Objects.nonNull(t.getExceptionHandler())) { if (Objects.nonNull(t.getExceptionHandler())) {
t.getExceptionHandler().accept(d); t.getExceptionHandler().accept(d);
......
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