我使用 Tomcat、Eclipse、Java EE、MongoDB。
当我运行要连接到 mongoDB 数据库并保存一些数据的 java 程序时,我收到此错误:
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版本,现在可以用了,谢谢