【发布时间】:2016-06-10 16:14:07
【问题描述】:
我有一个大文件(大约 3GB)并读入一个 ArrayList 当我运行下面的代码时,几分钟后代码运行速度非常慢并且 CPU 使用率很高。 几分钟后 Eclipse 控制台显示错误 java.lang.OutOfMemoryError: GC 开销限制超出。
- 操作系统:windows2008R2,
- 4 杯,
- 32GB 内存
- java版本“1.7.0_60”
eclipse.ini
-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20130327-1440.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.200.v20140116-2212
-product
org.eclipse.epp.package.standard.product
--launcher.defaultAction
openFile
#--launcher.XXMaxPermSize
#256M
-showsplash
org.eclipse.platform
#--launcher.XXMaxPermSize
#256m
--launcher.defaultAction
openFile
--launcher.appendVmargs
-vmargs
-Dosgi.requiredJavaVersion=1.6
-Xms10G
-Xmx10G
-XX:+UseParallelGC
-XX:ParallelGCThreads=24
-XX:MaxGCPauseMillis=1000
-XX:+UseAdaptiveSizePolicy
java代码:
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(new File("/words/wordlist.dat")));
InputStreamReader isr = new InputStreamReader(bis,"utf-8");
BufferedReader in = new BufferedReader(isr,1024*1024*512);
String strTemp = null;
long ind = 0;
while (((strTemp = in.readLine()) != null))
{
matcher.reset(strTemp);
if(strTemp.contains("$"))
{
al.add(strTemp);
strTemp = null;
}
ind = ind + 1;
if(ind%100000==0)
{
System.out.println(ind+" 100,000 +");
}
}
in.close();
我的用例:
neural network
java
oracle
solaris
quick sort
apple
green fluorescent protein
acm
trs
【问题讨论】:
-
你能详细说明你的用例吗?为什么内存中需要 3gb 的文件?
-
是否需要将整个文件加载到内存中?
-
你可以通过在eclipse配置中设置
-XX:-UseGCOverheadLimi来暂时防止这个问题:disable-the-usegcoverheadlimit-in-centos -
为什么不将 JVM 堆大小(不是 Eclipse!)增加到有点像 6gb?你显然有足够的内存 ;)
-
@haraldK 但那是针对 Eclipse,而不是它启动的 JVM
标签: java performance bufferedreader