private void checkIsUploadAndUpdateFile() { try { File folder = new File("D:/mapSycTrain/"); // 本地文件夹路径 File[] files = folder.listFiles(); if (files != null) { synchronized (allMapSycTrainMap) { for (File file : files) { String[] fileName1 = file.getName().split("-"); String[] fileName2 = fileName1[1].split("\."); Long trainingGroundIdByLocal = Long.valueOf(fileName1[0]);//文件训练场ID Long timeByLocal = Long.valueOf(fileName2[0]);//文件时间版本

                MapSycTrain value = allMapSycTrainMap.get(trainingGroundIdByLocal);
                if (value != null) {
                    if (!Objects.equals(value.time, timeByLocal)) {
                        // 开启新的线程去操作
                        Thread fileOperationThread = new Thread(() -> {
                            // 把Detail数据深拷贝一份,(使用io线程写入文件)将内存中的数据(深拷贝的数据)更新到本地json文件
                            List<DetailRouteMapData> detailRouteMapDataList = getDetailRouteMapDataListByTrainingGroundIdOrProjectRouteMapDataId(trainingGroundIdByLocal);
                            try {
                                List<DetailRouteMapData> copiedList = deepCopy(detailRouteMapDataList);
                                String json = JSON.toJSONString(copiedList);
                                String filePath = "D:/mapSycTrain/" + file.getName();
                                reName("D:/mapSycTrain/"+file.getName(),"D:/mapSycTrain/"+trainingGroundIdByLocal+"-"+value.time+".json");//修改文件名
                            } catch (IOException | ClassNotFoundException e) {
                                throw new RuntimeException(e);
                            }
                        });
                        fileOperationThread.start();
                    }
                } else {
                    // 删除无效文件
                    file.delete();
                }
            }
        }
    }
} catch (Exception e) {
    e.printStackTrace();
}
private void checkIsUploadAndUpdateFile try 1循环训练场allMapSycTrainMap中数据-加锁 synchronized allMapSycTrainMap for MapEntryLong MapSycTrain entry

原文地址: http://www.cveoy.top/t/topic/iNrz 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录