3

I use Tomcat, Eclipse, Java EE, MongoDB.

when I run my java program which is to connect to a mongoDB database and save some data, I get this error:

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

I have already changed the memory allowed by Eclipse, but I still have the same problem.

This is the code that causes the problem.

db.requestStart();
try 
{
    coll.insert(doc);
    DBObject err = db.getLastError();
} 
finally 
{
    db.requestDone();
}

PROBLEM SOLVED

The version of MongoDB was old and full of bug, I am now using version 2.8, and Now it's working, Thank you

7
  • Which versions of Tomcat, Java, MongoDB are you using? Commented Aug 7, 2012 at 9:21
  • I'm using Java 6, mongodb 2.0.6 & Apache TomEE 1.0.0 Commented Aug 7, 2012 at 9:36
  • 'allowed by Eclipse' means? Did you add memory settings in run configurations > Arguments Commented Aug 7, 2012 at 9:48
  • what is doc ? add the first line in try, System.out.println(doc); Commented Aug 7, 2012 at 9:50
  • @Tito George : I mean allocated (not allowed) Commented Aug 7, 2012 at 10:01

4 Answers 4

3

try to increase heap size

JVM -- keys
 -Xms<size>        set initial Java heap size
 -Xmx<size>        set maximum Java heap size
Sign up to request clarification or add additional context in comments.

Comments

2

Try to allow more memory for your JVM, with -Xmx1024m option (for example): How to deal with "java.lang.OutOfMemoryError: Java heap space" error (64MB heap size)

Comments

0

How much data are you trying to save? I think you are trying to store large amount of data in one shot to MongoDB.

1 Comment

There not a lot of data to save, just 10 rows
0

Edit these in Run Configurations For Run Configurations Right click your project root --> Run As--> Run Configurations

Add -Xms<size> and -Xmx<size> in VM arguments

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.