【问题标题】:I have changed memory size in eclipse but I'm still getting the java.lang.OutOfMemoryError我在 Eclipse 中更改了内存大小,但我仍然收到 java.lang.OutOfMemoryError
【发布时间】:2013-05-26 01:25:40
【问题描述】:

我正在运行一个 Java 程序,它从 1.2 GB 大的文件中逐行读取,并在某些时候尝试将它们放入哈希中。调用 taxhash.put(tmpgi,tmptax) 一段时间后,它给了我 java.lang.OutOfMemoryError 错误。

我尝试并更改了 eclipse.ini 选项如下

-startup
plugins/org.eclipse.equinox.launcher_1.1.1.R36x_v20101122_1400.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.2.R36x_v20101222
-product
org.eclipse.epp.package.jee.product
--launcher.defaultAction
openFile
--launcher.XXMaxPermSize
512M
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
512m
--launcher.defaultAction
openFile
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms2048m
-Xmx3548m

顺便说一句,我正在使用 4GB 内存的 64 位 win 7 上运行我的代码。这是从文件中读取的代码!

boolean readfile(String filename,int verbose){
        //this should read the inputfile and save the data in it to the gitax array.
        taxhash=new HashMap();
        int currnum=0;
        try{
            BufferedReader inread=new BufferedReader(new FileReader(filename));
            String instring;
            String[] tmparr;
            Integer tmpgi;
            Integer tmptax;
            if(verbose>0){
                while ((instring=inread.readLine())!=null){
                    currnum++;
                    instring=instring.trim();
                    tmparr=instring.split("\\s+",0);//split on one or more whitespaces
                    //now I should have two elements in this array, the gi number and the taxid
                    if(java.lang.reflect.Array.getLength(tmparr)!=2){
                        System.err.println("Error reading from "+filename+" "+java.lang.reflect.Array.getLength(tmparr)+" elements.");
                    }else{
                        try{
                            tmpgi=Integer.valueOf(tmparr[0]);
                            tmptax=Integer.valueOf(tmparr[1]);
                        }catch (NumberFormatException e){
                            System.err.println("unable to parse number from "+tmparr[0]+" "+tmparr[1]);
                            return false;
                        }
                        taxhash.put(tmpgi,tmptax);
                    }
                    if(currnum==100000){
                        System.out.print(".");
                        currnum=0;
                    }
                }
            }else{
                while ((instring=inread.readLine())!=null){
                    instring=instring.trim();
                    tmparr=instring.split("\\s+",0);//split on one or more whitespaces
                    //now I should have two elements in this array, the gi number and the taxid
                    if(java.lang.reflect.Array.getLength(tmparr)!=2){
                        System.err.println("Error reading from "+filename+" "+java.lang.reflect.Array.getLength(tmparr)+" elements.");
                    }else{
                        try{
                            tmpgi=Integer.valueOf(tmparr[0]);
                            tmptax=Integer.valueOf(tmparr[1]);
                        }catch (NumberFormatException e){
                            System.err.println("unable to parse number from "+tmparr[0]+" "+tmparr[1]);
                            return false;
                        }
                        taxhash.put(tmpgi,tmptax);
                    }
                }
            }
        }catch (IOException e){
            System.err.println("IOError in reading from "+filename);
            e.printStackTrace();
            return false;
        }
        return true;
    }// end readfile

这是线程“main”中的更多详细信息异常

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
    at java.util.HashMap.resize(Unknown Source)
    at java.util.HashMap.addEntry(Unknown Source)
    at java.util.HashMap.put(Unknown Source)
    at com.ali.Blammer.taxid.readfile(taxid.java:79)
    at com.ali.Blammer.taxid.readfile(taxid.java:50)
    at com.ali.Blammer.main.run(main.java:182)
    at com.ali.Blammer.blammer.main(blammer.java:36)
    at com.ali.Interface.main.main(main.java:53)

【问题讨论】:

    标签: java memory memory-management heap-memory


    【解决方案1】:

    您正在更改影响eclipse JVM 的内存选项,而不是您运行的程序的内存选项。

    在运行配置中,第二个选项卡允许为运行执行设置 JVM 参数。无论如何,我怀疑您能否将 1.2GB 的文件(加上哈希和其他开销)放入 512 MB

    【讨论】:

      【解决方案2】:

      您需要更改程序的大小而不是 Eclipse。由于您要存储 1.2 GB 的文本,因此您至少需要 2.4 Gb 的内存,但我怀疑需要接近 4 GB(有开销)

      由于您的机器很小,我建议您逐步处理文件以尽量减少内存消耗。

      顺便说一句:您可以使用比 HashMap 小得多的 TIntIntHashMap(最多小 4 倍),但对于您的数据集来说仍然可能太大。

      【讨论】:

      • 谢谢,但您所说的“逐步处理文件以尽可能减少内存消耗”是什么意思。
      • 而不是读取整个文件,在使用信息之前,通常可以使用文件的一部分并使用它,然后再读取一些等等。这假设你可以分解它方式。
      猜你喜欢
      • 2011-03-27
      • 2019-07-18
      • 2018-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多