修改日志展示逻辑
This commit is contained in:
@@ -13,6 +13,7 @@ import org.springframework.util.StopWatch;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/*
|
||||
@@ -27,7 +28,6 @@ public class HostInfoServiceImpl extends ServiceImpl<NewHostsMapper, NewHosts> i
|
||||
|
||||
@Override
|
||||
@Async("taskExecutor")
|
||||
|
||||
public CompletableFuture<Void> saveHostInfo(List<NewHosts> newHosts) {
|
||||
try {
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
@@ -35,11 +35,11 @@ public class HostInfoServiceImpl extends ServiceImpl<NewHostsMapper, NewHosts> i
|
||||
saveBatch(newHosts);
|
||||
stopWatch.stop();
|
||||
long totalTimeMillis = stopWatch.getTotalTimeMillis();
|
||||
log.info(" 存储花费: {}ms", totalTimeMillis);
|
||||
log.info("存储花费: {}ms", totalTimeMillis);
|
||||
return CompletableFuture.completedFuture(null);
|
||||
} catch (Exception e) {
|
||||
// 将异常包装到Future,使调用方能处理
|
||||
return CompletableFuture.failedFuture(e); // Java9+
|
||||
return CompletableFuture.failedFuture(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,6 +64,7 @@ public class HostInfoServiceImpl extends ServiceImpl<NewHostsMapper, NewHosts> i
|
||||
List<CompletableFuture<Void>> futures = new ArrayList<>();
|
||||
// 分片提交(避免单批次过大)
|
||||
Lists.partition(hosts, 1500).forEach(batch -> {
|
||||
log.info("当前存储数据量大小 {}", batch.size());
|
||||
CompletableFuture<Void> future = this.saveHostInfo(batch);
|
||||
futures.add(future);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user