From a2b6956497e23f03dcfa7c0a4d925224092bce6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E8=8B=B1=E6=9D=B0?= <327782001@qq.com> Date: Mon, 23 Oct 2023 00:24:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E6=94=B9=E5=88=86=E7=BB=84?= =?UTF-8?q?=E5=92=8C=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utils/FileContainsUtil.java | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/kwan/springbootkwan/utils/FileContainsUtil.java b/src/main/java/com/kwan/springbootkwan/utils/FileContainsUtil.java index 763c4bc..c577ff3 100644 --- a/src/main/java/com/kwan/springbootkwan/utils/FileContainsUtil.java +++ b/src/main/java/com/kwan/springbootkwan/utils/FileContainsUtil.java @@ -9,8 +9,10 @@ import lombok.extern.slf4j.Slf4j; import java.io.File; import java.io.IOException; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; +import java.util.Date; import java.util.List; import java.util.stream.Collectors; @@ -55,6 +57,7 @@ public class FileContainsUtil { public static void main(String[] args) throws Exception { StopWatch stopWatch = new StopWatch(); + currentTime("开始时间"); stopWatch.start("删除未用到的图片"); //不存在的图片集合 final List isNotExist = new ArrayList<>(); @@ -70,6 +73,7 @@ public class FileContainsUtil { log.info("耗时统计信息:{}", JSON.toJSONString(stopWatch.getTaskInfo())); log.info("耗时秒数:{}", JSON.toJSONString(stopWatch.getTotalTimeSeconds())); log.info("耗时分钟数:{}", JSON.toJSONString(stopWatch.getTotalTimeSeconds() / 60)); + currentTime("结束时间"); } /** @@ -81,7 +85,7 @@ public class FileContainsUtil { private static void moreThread(List> groupedPicNames, List isNotExist) { // 创建并启动4个线程来处理每个组的任务 List threads = new ArrayList<>(); - for (int i = 0; i < 8; i++) { + for (int i = 0; i < 6; i++) { final List group = groupedPicNames.get(i); Thread thread = new Thread(() -> { // 在这里执行处理图片组的任务 @@ -128,12 +132,13 @@ public class FileContainsUtil { /** * 数据分组 + * 经过测试6组和8组的时间基本一致,线程数并不是越大越好 * * @param picNames * @return */ private static List> dataGroup(List picNames) { - int groupSize = picNames.size() / 8; // 计算每组的大小 + int groupSize = picNames.size() / 6; // 计算每组的大小 List> groupedPicNames = picNames.stream() .collect(Collectors.groupingBy(e -> picNames.indexOf(e) / groupSize)) @@ -231,4 +236,19 @@ public class FileContainsUtil { System.err.printf("无法删除的路径 %s%n%s", picPath, e); } } + + /** + * 打印当前时间 + * + * @param str + */ + public static void currentTime(String str) { + // 获取当前时间 + Date currentTime = new Date(); + // 创建一个格式化器以将时间转换为所需的格式 + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + // 使用格式化器将时间转换为字符串并打印 + String formattedTime = dateFormat.format(currentTime); + System.out.println(str + ":" + formattedTime); + } } \ No newline at end of file -- GitLab