package com.gzlh.weighbridge.server; import cn.hutool.cache.CacheUtil; import cn.hutool.cache.impl.TimedCache; import cn.hutool.core.thread.ThreadUtil; import cn.hutool.log.StaticLog; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.stream.Collectors; public class CheckManager { private static String FLAG = "flag_key"; //读2秒的数据 private static TimedCache TASK_CACHE = CacheUtil.newTimedCache(6000); private static List WEIGHT_LIST = new CopyOnWriteArrayList<>(); public static boolean check() { Boolean result = TASK_CACHE.get(FLAG, false); return result != null&&result; } public static void setStart() { WEIGHT_LIST.clear(); TASK_CACHE.put(FLAG, true); StaticLog.info("开始称重--------"); //读取4秒的值 ThreadUtil.execute(new StartHandler()); } public static void setStop() { TASK_CACHE.put(FLAG, null); } public static void add(int weight) { WEIGHT_LIST.add(weight); } public static ListgetWeightList(){ return WEIGHT_LIST; } }