想要比较java中具有数十亿数据的两个映射的值吗

想要比较java中具有数十亿数据的两个映射的值吗,java,Java,我从数据库中获取一些值,并将其存储在地图中。现在我想比较两个地图的值并将其加载回数据库,但问题是,地图有100K的数据。现在,代码的编写方式是比较每个条目,例如,如果两个映射都有200k条目的条目,那么它将循环200k*200k次,需要几天时间。我需要分别比较字符串和长值 那么,有没有有效的方法进行比较,以避免不必要的循环 下面是已经编写的代码,它是非常旧的代码: 下面是getallMaps从数据库检索数据并存储在地图中的方法: protected Hashtable recordsList =

我从数据库中获取一些值,并将其存储在地图中。现在我想比较两个地图的值并将其加载回数据库,但问题是,地图有100K的数据。现在,代码的编写方式是比较每个条目,例如,如果两个映射都有200k条目的条目,那么它将循环200k*200k次,需要几天时间。我需要分别比较字符串和长值

那么,有没有有效的方法进行比较,以避免不必要的循环

下面是已经编写的代码,它是非常旧的代码:

下面是getallMaps从数据库检索数据并存储在地图中的方法:

protected Hashtable recordsList = new Hashtable();
protected Hashtable recordsListIC = new Hashtable();

public void getAllMaps() throws Exception {

    int count = 0;
    int i = 0;
    int j = 0;
    int k = 0;
    long nicPhyPort, nicId;
    String ipv4Val, ipv6Val;
    try {
        TRACE.debug("Ruuning pvc sql to get map");
        nicPVCStmt.setFetchSize(5000);
        ResultSet rs = nicPVCStmt.executeQuery();
        int rcnt = 0;
        while (rs.next()) {
            rcnt++;
            Hashtable rowNIC = new Hashtable();
            nicId = rs.getLong("ID");
            pvcid = rs.getLong("icore_pvc_id_value");
            nicPhyPort = rs.getLong("id_phy_port");
            nicSiteId = rs.getLong("id_site_inventory_site_rep");
            rowNIC.put("nicLogPort", nicId);
            rowNIC.put("nicPhyPort", nicPhyPort);
            rowNIC.put("nicPvc", pvcid);
            rowNIC.put("nicSite", nicSiteId);
            recordsList.put(count, rowNIC);
            count++;
        }

        if (rs != null) rs.close();
        getIcorePVCUnifiedRec.setFetchSize(5000);
        rs = getIcorePVCUnifiedRec.executeQuery();
        int rcnt1 = 0;
        while (rs.next()) {
            rcnt1++;
            Hashtable row = new Hashtable();
            icoreId = rs.getLong("ID");
            icorephyid = rs.getLong("id_phy_port");
            pvcid = rs.getLong("icore_pvc_id_value");
            row.put("icoreId", icoreId);
            row.put("icPhyPort", icorephyid);
            row.put("pvcId", pvcid);

            recordsListIC.put(i, row);
            i++;
        }

        if (rs != null) rs.close();

    } catch (Exception ex) {
        ex.getMessage();
        ex.printStackTrace();
    }
}
以下是用于比较地图的CheckPvCunification方法:

地图recordsList和recordsList都有数十亿的数据,由于第二个for循环,它需要花费大量时间

public void checkPVCUnificationApplies(Connection gcon) throws Exception {
    long icoreId, icorePVC, phyPortId;

    int cnt = 0;
    try {
        TRACE.debug("checkUnificationApplies--");
        for (int i = 0; i < recordsList.size(); i++) {

            Hashtable tbl = (Hashtable) recordsList.get(i);
            //TRACE.debug("under check for table "+tbl);
            long nonIcid = (Long) tbl.get("nicLogPort");
            long pvcValue = (Long) tbl.get("nicPvc");
            long nicPhyPortid = (Long) tbl.get("nicPhyPort");
            long nicSiteid = (Long) tbl.get("nicSite");
            for (int j = 0; j < recordsListIC.size(); j++) {
                //TRACE.debug("List item iteration-->"+j);
                Hashtable pvcTbl = (Hashtable) recordsListIC.get(j);
                TRACE.debug("under pvcTbl  for  values " + pvcTbl);
                icoreId = (Long) pvcTbl.get("icoreId");
                icorePVC = (Long) pvcTbl.get("pvcId");
                phyPortId = (Long) pvcTbl.get("icPhyPort");
                //icSite=(Long)pvcTbl.get("icPhyPort");
                TRACE.debug("Matching " + pvcValue + " with " + icorePVC);
                if (pvcValue == icorePVC) {
                    icoreId = unify.geocodeMatchFound(nicSiteid, icoreId, gcon);
                    if (icoreId > 0) {
                        TRACE.debug("all values icoreId and nonIcore " + icoreId + ":" + nonIcid + " with " + phyPortId + nicPhyPortid);
                        cs.setLong(1, icoreId);
                        cs.setLong(2, nonIcid);
                        cs.setLong(3, phyPortId);
                        cs.setLong(4, nicPhyPortid);
                        cs.addBatch();
                        cnt++;
                    }
                }

                if (cnt % 50000 == 0) {
                    cs.executeBatch();
                    cnt = 0;
                }
            }
        }
        if (cnt > 0) {
            cs.executeBatch();
            TRACE.debug("executed batch for >0" + cnt);
        }
        recordsList.clear();
    } catch (Exception e) {
        e.getMessage();
        e.printStackTrace();
    }
}

我不擅长Java,所以请告诉我是否有更有效的方法来比较上述映射。

如果您可以选择使用PL/SQL之类的DB过程,请在那里执行,而不是在您的程序中执行。它将大大提高性能


如果您真的想提取数据并在程序中进行比较,那么这是速度、时间和资源之间的权衡。如果您想要快速的性能,那么就添加更多的资源,并设计一个有效的算法来获取分块比较的数据

可能你忘记粘贴代码了。对于想知道一个Lakh是什么样的人来说:一个Lakh似乎是10万个东西的印度表达:-请通过比较两张地图的值来澄清你的意思。现在真的不清楚了。@MChaker抱歉伙计们添加了上面的代码。。。。请告诉我有效的代码