Java multithreaded data generation duplication

this is a piece of code in our business. The main logic is to group data according to bank accounts, and each group, that is, each bank account, has a thread to process business logic.
the problem now is that duplicate data is generated in a small probability on the cable, and local tests try to restore the scenario, but the problem cannot be reproduced all the time.

related codes

this is the entity writeOffDailyReport. entered into the library. That is, the entity is repeated when it is generated.

ExecutorService cachedThreadPool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()*2);
List<Future> futures = Lists.newArrayList();
for (String value : Sets.newHashSet(multimap.keys())) {
                futures.add(cachedThreadPool.submit(() -> {
                    Thread thread = Thread.currentThread();
                    logger.info("," +
                            ": " + value + ",: id" + thread.getId() + " " + thread.getName());
                    values.add(value);
                    List<WriteOffDailyReport> subList = Lists.newArrayList();
                    BigDecimal initAmount = BigDecimal.ZERO;
                    BigDecimal finalAmount = BigDecimal.ZERO;
                    BigDecimal bankDifferenceBD = BigDecimal.ZERO;
                    List<AnalysisBankBillVo> analysisBankBillVoList = this.getAnalysisBankBillthrowEx(MyUtils.formatNumber(value), exportDate);
                    WriteOffDailyReport reportFromAnalysisBankBill = this.setValueFromAnalysisBankBill(analysisBankBillVoList);
                    logger.info(": " + value + " ");
                    for (WriteOffData writeOffDataExample : Lists.newArrayList(multimap.get(value))) {
                        logger.info(" : " + value + " : " + writeOffDataExample.getOrgName());
                        WriteOffDailyReport writeOffDailyReport = new WriteOffDailyReport();
                        writeOffDailyReport.setStatus("00");
                        this.setValueFromWriteOffData(exportDate, writeOffDataExample, writeOffDailyReport);
                        List<OrgConfig> orgConfigs = this.setValueFromOrgConig(writeOffDailyReport, orgConfigMultimap, writeOffDataExample);
                        this.setValueFromYesterDayReport(exportDate, writeOffDailyReport);
                        initAmount = new BigDecimal(writeOffDailyReport.getBankInitialBalance());
                        finalAmount = new BigDecimal(writeOffDailyReport.getBankFinalBalance());
                        bankDifferenceBD = this.computeBankDifference(bankDifferenceBD, writeOffDailyReport);
                        this.computeBusinessIncome(writeOffDailyReport);
                        this.computeBankIncomeOrPayout(writeOffDailyReport, orgConfigs);
                        this.setValueFromReportAnalysisBankBill(reportFromAnalysisBankBill, writeOffDailyReport);
                        subList.add(writeOffDailyReport);
                        logger.info(": " + value + " : " + writeOffDataExample.getOrgName() + " !");
                    }
                    logger.info(": " + value + " ");
                    bankDifferenceBD = computeBankDifferenceExpand(bankDifferenceBD, reportFromAnalysisBankBill);
                    logger.info("/");
                    for (WriteOffDailyReport dailyReport : subList) {
                        dailyReport.setBankDifference(MyUtils.initValue(initAmount.add(bankDifferenceBD).subtract(finalAmount).toPlainString()));
                        this.sortListFromDailyReport(batchAdd, batchUpdate, dailyReport);
                    }
                    return true;
                }));
            }
now multithreading is removed from running, which is a bit inefficient. I am still not familiar with multithreading. Please give me some advice.
Mar.23,2022

 List<AnalysisBankBillVo> analysisBankBillVoList = this.getAnalysisBankBillthrowEx(MyUtils.formatNumber(value), exportDate);
 WriteOffDailyReport reportFromAnalysisBankBill = this.setValueFromAnalysisBankBill(analysisBankBillVoList);      

should be the logic problem generated here. It's hard to say if you don't see it in there. Is future necessary? if it is not necessary, remove it first and check it step by step. There is certainly no problem with this mode of use.

Menu