https://pastein.ru/t/Sl

  скопируйте уникальную ссылку для отправки


   
Данные из heapDump - на момент средних зависаний в Heap дампе находилось более миллиарда объектов ResultSet и более 300 не закрытых соединений c бд.

public void getDynData(int labId) {
        Iterator var2 = this.rowsCount.entrySet().iterator(); 

        while(var2.hasNext()) {                                                                          //цикл, который может доходить до 22000 итераций (по количеству документов в базе)
            Entry<String, Integer> entry = (Entry)var2.next();
            int count = (Integer)entry.getValue();

            try {
                Connection con = ConnectionUtil.getXAConnection();                                       // открываем одно соединение

                try {
                    label56:                                                                              
                    for(int i = 1; i <= count; ++i) {   // еще цикл
                        PreparedStatement preparedStatement = con.prepareStatement(this.sqlDynData(i));  //открываем PrepearedStatement и ResultSet
                        preparedStatement.setString(1, (String)entry.getKey());
                        ResultSet set = preparedStatement.executeQuery();

                        while(true) {                                                                    //запускаем бесконечный цикл, который не закроется и оставит все наши соединения и resultset открытыми
                            int labCode;
                            do {                                                                          //запускаем еще цикл (Сложность алгоритма уже в районе O(n^4))
                                if (!set.next()) {
                                    continue label56;                                                           

                                if (labId <= 0) {
                                    break;
                                }

                                labCode = NumberUtils.parseInt(this.getValue(set, "labCode"));
                            } while(labCode != labId); 
  
                            ReestrModel reestrModel = new ReestrModel();                       
                            reestrModel.setDocumentID((String)entry.getKey());
                            reestrModel.setResName(this.getValue(set, "resname"));
                            reestrModel.setLabName(this.getValue(set, "labname"));
                            reestrModel.setLabNameCode(this.getValue(set, "labCode"));
                            reestrModel.setResGroup(this.getValue(set, "resgroup"));
                            reestrModel.setResGroupCode(this.getValue(set, "resGroupCode"));
                            reestrModel.setSubResGroup(this.getValue(set, "subresgroup"));
                            reestrModel.setSubResGroupCode(this.getValue(set, "subresgroupCode"));
                            reestrModel.setResMethod(this.getValue(set, "resmethod"));
                            reestrModel.setSerUnit(this.getValue(set, "serunit"));
                            reestrModel.setCoeficient(this.getValue(set, "coeficient"));
                            reestrModel.setTarCode(this.getValue(set, "tarcode"));
                            reestrModel.setBaseRate(this.getValue(set, "base_rate"));
                            reestrModel.setSerAmount(this.getValue(set, "seramount"));
                            reestrModel.setmSerAmount(this.getValue(set, "mseramount"));
                            reestrModel.setSubLabName(this.getValue(set, "subLabName"));
                            reestrModel.setSubLabNameCode(this.getValue(set, "subLabNameCode"));
                            this.reestrModels.add(reestrModel);                                
                        }
                    }
                } catch (Throwable var11) {                                                             // до сюда даже не дойдем из-за бесконечного цикла, соответственно ничего не закроем
                    if (con != null) {
                        try {
                            con.close();
                        } catch (Throwable var10) {
                            var11.addSuppressed(var10);
                        }
                    }

                    throw var11;
                }

                if (con != null) {
                    con.close();
                }
            } catch (Exception var12) {
                ;
            }
        }

    }