解决 java.lang.OutOfMemoryError:Java 堆空间
正如标题所示,我在线程中遇到此错误。
违规的 LOC 如下所示:
for (int i = 0; i < objectListSize; i++) {
logger.INFO("Loop repeat: "+i+" ...", true);
final Double discreteScore = sp.getDouble(superPeerSocket);
final int expectedObjectIDs = sp.getInteger(superPeerSocket);
final String discreteObjects[] = new String[expectedObjectIDs];
for ( int j = 0; j < expectedObjectIDs; j++)
discreteObjects[j] = sp.getString(superPeerSocket);
htPlus.attachInitialDiscreteList2L1(discreteScore, discreteObjects);
}
The final String discreteObjects[] declaration is where I get the error. I am running this code inside a thread. I have two threads currently active when I get this. I also tried using the MAT tool from eclipse. here is a link with some chart files inside: PLC chart files (dropbox URL)If anyone has any idea for this problem I would be grateful. P.S.: I am thinking to remove the loop although it just fails in the first loop pass.
(I get this in the output when the program fails)
Expected data size: 10
Repeat: 0 ...
java.lang.OutOfMemoryError: Java heap space
Dumping heap to java_pid3793.hprof ...
Heap dump file created [1404020 bytes in 0.015 secs]
Exception in thread "1" java.lang.OutOfMemoryError: Java heap space
at planetlab.app.factory.Worker$15.run(Worker.java:796)
at java.lang.Thread.run(Thread.java:662)
Something irrelevant:What's with the code not properly formatted/intended error when making posts in stack overflow? It took me 15 minutes to figure out what to do :@ :S :@
As the title suggests I'm getting this error inside a thread.
The offending LOCs looks like this:
for (int i = 0; i < objectListSize; i++) { logger.INFO("Loop repeat: "+i+" ...", true); final Double discreteScore = sp.getDouble(superPeerSocket); final int expectedObjectIDs = sp.getInteger(superPeerSocket); final String discreteObjects[] = new String[expectedObjectIDs]; for ( int j = 0; j < expectedObjectIDs; j++) discreteObjects[j] = sp.getString(superPeerSocket); htPlus.attachInitialDiscreteList2L1(discreteScore, discreteObjects); }
The final String discreteObjects[] declaration is where I get the error. I am running this code inside a thread. I have two threads currently active when I get this. I also tried using the MAT tool from eclipse. here is a link with some chart files inside:
PLC chart files (dropbox URL)
If anyone has any idea for this problem I would be grateful.
P.S.: I am thinking to remove the loop although it just fails in the first loop pass.
(I get this in the output when the program fails)
Expected data size: 10 Repeat: 0 ... java.lang.OutOfMemoryError: Java heap space Dumping heap to java_pid3793.hprof ... Heap dump file created [1404020 bytes in 0.015 secs] Exception in thread "1" java.lang.OutOfMemoryError: Java heap space at planetlab.app.factory.Worker$15.run(Worker.java:796) at java.lang.Thread.run(Thread.java:662)
Something irrelevant:
What's with the code not properly formatted/intended error when making posts in stack overflow? It took me 15 minutes to figure out what to do :@ :S :@
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每个 Java 程序都运行在沙箱中。虽然您的操作系统可能有 10 GB 可用 RAM,但您的应用程序可能只有 128 MB。
您需要使用 -Xms -Xmx 参数确保您的应用程序有足够的内存分配给 JVM。 -Xms 表示最小值,-Xmx 表示最大值
评论中建议您的预期ObjectID 似乎有点高。我当然会检查一下。但是,您可以使用以下代码来了解内存使用情况和可用内存。使用该信息,您可以相应地调整您的 -Xms -Xmx 。
祝你好运!
Every Java program runs in a sandbox. While your OS might have 10 GB of RAM available to it your app might only have 128 MB.
You need to make sure you app has enough ram allocated to the JVM by using the -Xms -Xmx arguments. -Xms indicates the minimum and -Xmx the maximum
It's been suggested in the comments that your expectedObjectIDs seem kinda high. I would certainly check that out. However, you can use the following code to get an idea as you to memory usage and available memory. Using that info you can adjust your -Xms -Xmx accordingly.
Good luck!