我在eclipse中更改了内存大小,但我';我仍然得到java.lang.OutOfMemoryError
我正在运行一个Java程序,它从一个1.2GB大小的文件中逐行读取数据,并在某个时候尝试将它们放入散列。调用taxhash.put(tmpgi,tmptax)一段时间后,它给出了java.lang.OutOfMemoryError错误 我尝试并更改了eclipse.ini选项,如下所示我在eclipse中更改了内存大小,但我';我仍然得到java.lang.OutOfMemoryError,java,memory,memory-management,heap,heap-memory,Java,Memory,Memory Management,Heap,Heap Memory,我正在运行一个Java程序,它从一个1.2GB大小的文件中逐行读取数据,并在某个时候尝试将它们放入散列。调用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
-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
顺便说一句,我的代码运行在64位Win7上,内存为4GB。这是读取文件的代码
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”中“更多详细信息”异常中的错误
您正在更改影响
eclipse
JVM的内存选项,而不是您运行的程序的内存选项
在运行配置中,第二个选项卡允许为运行执行设置JVM参数。无论如何,我怀疑您是否能将1.2GB的文件(加上散列和其他开销)放入512 MB中,因为您正在更改影响eclipse JVM的内存选项,而不是您运行的程序的内存选项
在运行配置中,第二个选项卡允许为运行执行设置JVM参数。无论如何,我怀疑你是否能将1.2GB的文件(加上散列和其他开销)放到512MB中。你需要更改程序的大小,而不是eclipse。由于您要存储1.2GB的文本,您至少需要2.4GB的内存,但我怀疑需要接近4GB的内存(有开销) 由于您有一台小型计算机,我建议您逐步处理该文件,以尽可能减少内存消耗
顺便说一句:您可以使用比HashMap小得多的TIntIntHashMap(最多小4倍),但对于您的数据集来说可能仍然太多。您需要更改程序的大小,而不是eclipse。由于您要存储1.2GB的文本,您至少需要2.4GB的内存,但我怀疑需要接近4GB的内存(有开销) 由于您有一台小型计算机,我建议您逐步处理该文件,以尽可能减少内存消耗
顺便说一句:你可以使用TIntIntHashMap,它比HashMap小很多(最多小4倍),但是对于你的数据集来说可能还是太多了。谢谢,但是你所说的“逐步处理文件以尽可能减少内存消耗”是什么意思呢,通常可以使用文件的一部分并使用它,然后再阅读一些其他内容。这假设您可以这样分解它。谢谢,但您所说的“逐步处理文件以尽可能减少内存消耗”是什么意思。在使用信息之前,您不必阅读整个文件,通常可以使用文件的一部分并使用它,然后再读取一些其他内容。这假设您可以通过这种方式将其分解。
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)