Commit 3b89d155 authored by lihao's avatar lihao

add logging

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