简体   繁体   English

如何在Eclipse中修复OutOfMemoryError [Java堆空间]

[英]How to fix OutOfMemoryError[Java heap space] in Eclipse

I am accessing elasticsearch from my java code in Eclipse and dumping all the data to my local drive. 我正在从Eclipse中的Java代码访问elasticsearch,并将所有数据转储到本地驱动器。 There is around 1GB of data. 大约有1GB的数据。

My program worked till 300MB of data but after that when I try to run my code in eclipse it throws the following error: 我的程序可以工作到300MB的数据,但是在此之后,当我尝试在eclipse中运行代码时,它将引发以下错误:

{
  "error" : "OutOfMemoryError[Java heap space]",
  "status" : 500
}

I saw online it's mentioned to add -Xmx2048M under Run > Run Config for the class I am running. 我在网上看到有人提到在我正在运行的类的“运行”>“运行配置”下添加-Xmx2048M I tried that and restarted eclipse, still getting the same error. 我尝试了一下,然后重新启动了eclipse,仍然收到相同的错误。

Please advice. 请指教。 Thanks. 谢谢。

Are you trying to store the whole data into memory? 您是否正在尝试将所有数据存储到内存中? Do no do that. 不要那样做。

Try to use the streaming API's from Java which will dump the data to secondary storage once the stream is full. 尝试使用Java的流API,一旦流已满,它将把数据转储到辅助存储中。 You can define the max buffer size as per your RAM available. 您可以根据可用的RAM定义最大缓冲区大小。

Looks like the error message is coming from Elastic search and not from your Java Program. 看起来错误消息是来自Elastic搜索而不是Java程序。

Use this page to configure bigger heap for elastic search. 使用此页面为弹性搜索配置更大的堆。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM