在 Eclipse 中增加堆空间:(java.lang.OutOfMemoryError) [英] Increasing heap space in Eclipse: (java.lang.OutOfMemoryError)

查看:19
本文介绍了在 Eclipse 中增加堆空间:(java.lang.OutOfMemoryError)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

try {
    // CompareRecord record = new CompareRecord();
    Connection conn = new CompareRecord().getConection("eliteddaprd","eliteddaprd","192.168.14.104","1521");
    ResultSet res = null;

    if (conn != null){
        Statement stmt = conn.createStatement();
        res = stmt.executeQuery("select rowindx,ADDRLINE1 from dedupinitial order by rowindx");
    }

    Map<Integer,String> adddressMap = new LinkedHashMap<Integer, String>();
    if (res != null){
        System.out.println("result set is not null ");
        while(res.next()){
            adddressMap.put(res.getInt(1),res.getString(2));
        }
    }

    System.out.println("address Map size =========> "+adddressMap.size());
    Iterator it = adddressMap.entrySet().iterator();
    int count = 0;
    int min = 0;

    while (it.hasNext()){
        Map.Entry pairs = (Map.Entry)it.next();
        Pattern p = Pattern.compile("[,\s]+");
        Integer outerkey = (Integer)pairs.getKey();
        String outerValue = (String)pairs.getValue();
        //System.out.println("outer Value ======> "+outerValue);

        String[] outerresult = p.split(outerValue);
        Map.Entry pairs2 = null;
        count++;
        List<Integer> dupList = new ArrayList<Integer>();

        Iterator innerit = adddressMap.entrySet().iterator();
        boolean first = true;

        while (innerit.hasNext()){
            //System.out.println("count value ===> "+count);
            int totmatch = 0;
            if(first){
                if(count == adddressMap.size()){
                    break;
                }
                for(int i=0;i<=count;i++){
                    pairs2 = (Map.Entry)innerit.next();
                }
                first  = false;
            }
            else{
                pairs2 = (Map.Entry)innerit.next();
            }
            Integer innterKey = (Integer)pairs2.getKey();
            String innerValue = (String)pairs2.getValue();
            //System.out.println("innrer value "+innerValue);
            String[] innerresult = p.split(innerValue);

            for(int j=0;j<outerresult.length;j++){
                for(int k=0;k<innerresult.length;k++){
                    if(outerresult[j].equalsIgnoreCase(innerresult[k])){
                        //System.out.println(outerresult[j]+" Match With "+innerresult[k]);
                        totmatch++;
                        break;
                    }
                }
            }

            min = Math.min(outerresult.length, innerresult.length);
            if(min != 0 && ((totmatch*100)/min) > 50) {
                //System.out.println("maching inner key =========> "+innterKey);
                dupList.add(innterKey);
            }
        }
        //System.out.println("Duplilcate List Sisze ===================> "+dupList.size()+"   "+outerkey);
    }

    System.out.println("End  =========> "+new Date());
}
catch (Exception e) {
    e.printStackTrace();
}

这里的 ResultSet 已经处理了大约 500000 条记录,但它会给我这样的错误:

Here ResultSet have processed around 500000 records, but it will give me error like:

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
    at java.util.HashMap.resize(HashMap.java:508)
    at java.util.LinkedHashMap.addEntry(LinkedHashMap.java:406)
    at java.util.HashMap.put(HashMap.java:431)
    at spite.CompareRecord.main(CompareRecord.java:91)

我知道这个错误是因为VM内存,但不知道如何在Eclipse中增加它?

I know this error comes because of VM memory, but don't know how to increase it in Eclipse?

如果我必须处理超过 500,000 条记录,我该怎么办?

What do I do if I have to process even more than 500,000 records?

推荐答案

在 Run->Run Configuration 中找到你一直在运行的类的 Name,选择它,点击 Arguments 选项卡,然后添加:

In Run->Run Configuration find the Name of the class you have been running, select it, click the Arguments tab then add:

-Xms512M -Xmx1524M

-Xms512M -Xmx1524M

到VM参数部分

这篇关于在 Eclipse 中增加堆空间:(java.lang.OutOfMemoryError)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆