package org.example.file;import java.util.concurrent.ConcurrentHashMap;public class FileHelper {private FileService fileService;//全局唯一,用于控制文件时间全局唯一//value:0:没被消费,1:被消费public static final ConcurrentHashMap<Long, Integer> MONITOR_MAP = new ConcurrentHashMap<>();public Boolean checkTimeSingle(){int i = 0;while (i != 100) {//当前线程时间Long currentTime = System.currentTimeMillis();if (MONITOR_MAP.containsKey(currentTime)) {//判断是否被消费if (MONITOR_MAP.get(currentTime) == 0) {if (fileService.saveFile()) {//如果消费成功改为1并删除MONITOR_MAP.put(currentTime, 1);MONITOR_MAP.remove(currentTime);return true;} else {return false;}}} else {MONITOR_MAP.put(currentTime, 0);i++;}}return false;}}