我使用Tomcat,Eclipse,Java EE,MongoDB。
当我运行我的java程序连接到mongoDB数据库并保存一些数据时,我收到此错误:
Exception in thread "http-bio-8080-exec-19"
java.lang.OutOfMemoryError: Java heap space
at java.nio.HeapCharBuffer.<init>(HeapCharBuffer.java:57)
at java.nio.CharBuffer.allocate(CharBuffer.java:331)
at com.mongodb.ByteEncoder.<init>(ByteEncoder.java:546)
at com.mongodb.ByteEncoder.<init>(ByteEncoder.java:48)
at com.mongodb.ByteEncoder$1.createNew(ByteEncoder.java:79)
at com.mongodb.ByteEncoder$1.createNew(ByteEncoder.java:76)
at com.mongodb.util.SimplePool._get(SimplePool.java:140)
at com.mongodb.util.SimplePool.get(SimplePool.java:106)
at com.mongodb.util.SimplePool.get(SimplePool.java:95)
at com.mongodb.ByteEncoder.get(ByteEncoder.java:66)
at com.mongodb.DBMessage.<init>(DBMessage.java:52)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:166)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:132)
at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:127)
at web.ApplicationInterface.doGet(ApplicationInterface.java:125)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110),
EDIT
我已经改变了Eclipse允许的内存,但我仍然遇到同样的问题。
这是导致问题的代码。
db.requestStart();
try
{
coll.insert(doc);
DBObject err = db.getLastError();
}
finally
{
db.requestDone();
}
PROBLEM SOLVED
MongoDB的版本很旧且充满了bug,我现在使用的是2.8版本,现在它正在运行,谢谢
答案 0 :(得分:3)
尝试增加堆大小
JVM -- keys
-Xms<size> set initial Java heap size
-Xmx<size> set maximum Java heap size
答案 1 :(得分:2)
尝试为JVM提供更多内存,并使用-Xmx1024m
选项(例如):How to deal with "java.lang.OutOfMemoryError: Java heap space" error (64MB heap size)
答案 2 :(得分:0)
您想要保存多少数据? 我认为你试图将大量数据一次性存储到MongoDB中。
答案 3 :(得分:0)
在“运行配置”中编辑这些内容 对于运行配置 右键单击您的项目根目录 - &gt;运行方式 - &gt;运行配置