Results 1 to 19 of 19
  1. #1
    babyboban is offline Member
    Join Date
    Jan 2010
    Posts
    7
    Rep Power
    0

    Default Java heap space,

    HI all,
    I am facing the following exception. My project struture is Spring+struts+mysql


    java.lang.OutOfMemoryError: Java heap space
    at sun.util.resources.TimeZoneNames.getContents(TimeZ oneNames.java:175)
    at sun.util.resources.OpenListResourceBundle.loadLook up(OpenListResourceBundle.java:109)
    at sun.util.resources.OpenListResourceBundle.loadLook upTablesIfNecessary(OpenListResourceBundle.java:97 )
    at sun.util.resources.OpenListResourceBundle.handleGe tObject(OpenListResourceBundle.java:58)
    at sun.util.resources.TimeZoneNamesBundle.handleGetOb ject(TimeZoneNamesBundle.java:59)
    at java.util.ResourceBundle.getObject(ResourceBundle. java:378)
    at java.util.ResourceBundle.getObject(ResourceBundle. java:381)
    at java.util.ResourceBundle.getStringArray(ResourceBu ndle.java:361)
    at sun.util.TimeZoneNameUtility.retrieveDisplayNames( TimeZoneNameUtility.java:100)
    at sun.util.TimeZoneNameUtility.retrieveDisplayNames( TimeZoneNameUtility.java:81)
    at java.util.TimeZone.getDisplayNames(TimeZone.java:3 99)
    at java.util.TimeZone.getDisplayName(TimeZone.java:35 0)
    at java.text.SimpleDateFormat.subFormat(SimpleDateFor mat.java:1092)
    at java.text.SimpleDateFormat.format(SimpleDateFormat .java:881)
    at java.text.SimpleDateFormat.format(SimpleDateFormat .java:851)
    at java.text.DateFormat.format(DateFormat.java:316)
    at org.apache.tomcat.util.http.FastHttpDateFormat.get CurrentDate(FastHttpDateFormat.java:110)
    at org.apache.coyote.http11.Http11Processor.prepareRe sponse(Http11Processor.java:1596)
    at org.apache.coyote.http11.Http11Processor.action(Ht tp11Processor.java:968)
    at org.apache.coyote.Response.action(Response.java:18 3)
    at org.apache.coyote.Response.sendHeaders(Response.ja va:379)
    at org.apache.catalina.connector.OutputBuffer.doFlush (OutputBuffer.java:317)
    at org.apache.catalina.connector.OutputBuffer.close(O utputBuffer.java:278)
    at org.apache.catalina.connector.Response.finishRespo nse(Response.java:484)
    at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:177)
    at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:875)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11 ConnectionHandler.processConnection(Http11BaseProt ocol.java:665)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.process Socket(PoolTcpEndpoint.java:528)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThr ead.runIt(LeaderFollowerWorkerThread.java:81)
    at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:689)
    at java.lang.Thread.run(Thread.java:619)



    please help me

  2. #2
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    6

    Default

    Your program needs more memory than that is allocated. To allocate more memory, launch your program with the parameter -xmx[MEMORY]m
    So, for example, if you want to raise the maximum memory to 512mb, use java -xmx512m javaprogram
    To set a minimum amount of memory, use -xms
    I die a little on the inside...
    Every time I get shot.

  3. #3
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    Supamagier is correct about increasing your heap size. However, I'd be surprised if that is the whole problem. Try increasing the -xmx, and if that solves the problem, then fine. However, I suspect that somewhere in your code, you are repeatedly creating instances that cannot be garbage collected. One way to do that is to create many instances of some class and then to add them to a list.

  4. #4
    masternerdguy is offline Member
    Join Date
    Jan 2010
    Posts
    9
    Rep Power
    0

    Default

    are you using lots of resource files (images, databases, plain text files, etc)? If you are, then I feel your pain. I was writing a space RPG a while back and to prevent the heap from overflowing I gave it 128mb of ram and wrote my own garbage collector to unload images that do not need to be rendered.

    Edit:

    Another idea is to save your consistantly larger variables to a file and unload them until needed, this can be feasable in some situations where the variable is used less often than the time it takes to read and write it.

  5. #5
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    Just to chime in, 128M is pretty small for a Web app server. Try 512M...

  6. #6
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    Or you can flush the memory when you come across with OutOfMemoryError :
    Java Code:
    import java.util.Vector;
    
    import org.apache.log4j.Logger;
    
    public class FlushMemoryRunner {
    
        private final static Logger log = Logger.getLogger(FlushMemoryRunner.class
                .getName());
    
        public static void flushMemory() {
            if (log.isInfoEnabled())
                log.info("Flushing memory in the Runtime");
            //Use a vector to hold the memory.
            Vector v = new Vector();
            int count = 0;
            //increment in megabyte chunks initially
            int size = 1048576;
            //Keep going until we would be requesting 
            //chunks of 1 byte
            while (size > 1) {
                try {
                    for (; true; count++) {
                        //request and hold onto more memory
                        v.addElement(new byte[size]);
                    }
                } catch (OutOfMemoryError bounded) {
                    log.error("We encoutered a GC limit exceeded");
                    size = size / 2;
                    if (log.isInfoEnabled())
                        log
                                .info("Trying to get more memory, but asking for the chunks half as big");
                }
            }
            if (log.isInfoEnabled())
                log.info("Releasing everything for GC");
            v = null;
            //and ask for a new Vector as a new small object 
            //to make sure garbage collection kicks in before 
            //we exit the method.
            v = new Vector();
            if (log.isInfoEnabled())
                log.info("The free memory after memory flushing: "
                        + Runtime.getRuntime().freeMemory());
        }
    
    }
    I use it very often

  7. #7
    babyboban is offline Member
    Join Date
    Jan 2010
    Posts
    7
    Rep Power
    0

    Default

    thx, for all of your valuable comments, about the issue

  8. #8
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Quote Originally Posted by serjant View Post
    Or you can flush the memory when you come across with OutOfMemoryError ...
    If an OutOfMemoryError has occurred, it is guaranteed that garbage collection was run and it didn't help in stopping the error.

  9. #9
    babyboban is offline Member
    Join Date
    Jan 2010
    Posts
    7
    Rep Power
    0

    Default

    this is the code, which, showing the exception,

    public void saveNewIdnoAndVerificationNumberImplict(PartnerFor m partnerForm, int noOfKeytoBeProduce,String product_type,String customerCode,
    String keyFinderType,Long partnerConnectorId,String serviceProfile,String runningTimeFrom,String runningTimeTill){

    SessionFactory sessionFactory = this.getSessionFactory();
    session =sessionFactory.openSession();
    Transaction T= session.beginTransaction();

    try{



    PartnerForm partnerFormTest = null;

    for (int j=0;j<noOfKeytoBeProduce;j++){
    partnerFormTest=new PartnerForm();
    String newIdno=getNewIdno();

    partnerFormTest.setFinder_status("available");
    partnerFormTest.setIdentification_no(newIdno);
    partnerFormTest.setVerification_no(getNewVerificat ionNumber(customerCode.toUpperCase(), newIdno, product_type));
    partnerFormTest.setKeyfinder_type(keyFinderType) ;

    partnerFormTest.setPartner_connector_id(partnerCon nectorId);
    partnerFormTest.setRunning_time_batch_status("inac tive");
    partnerFormTest.setService_profile(serviceProfile) ;
    partnerFormTest.setSms_action("");

    session.save(partnerFormTest);


    if(noOfKeytoBeProduce % 30==0){
    //30, same as the JDBC batch size
    //flush a batch and release memory
    session.flush();
    session.clear();
    }
    }//for (int j=0;j<noOfKeytoBeProduce;j++)
    T.commit();


    }catch (Exception e) {
    sfException.showException("AdminDAOImpl,saveNewIdn oAndVerificationNumberImplict:"+e);
    }


    }

    I am facing the following exception. My project struture is Spring+struts+mysql


    java.lang.OutOfMemoryError: Java heap space
    at sun.util.resources.TimeZoneNames.getContents(TimeZ oneNames.java:175)
    at sun.util.resources.OpenListResourceBundle.loadLook up(OpenListResourceBundle.java:109)
    at sun.util.resources.OpenListResourceBundle.loadLook upTablesIfNecessary(OpenListResourceBundle.java:97 )
    at sun.util.resources.OpenListResourceBundle.handleGe tObject(OpenListResourceBundle.java:58)
    at sun.util.resources.TimeZoneNamesBundle.handleGetOb ject(TimeZoneNamesBundle.java:59)
    at java.util.ResourceBundle.getObject(ResourceBundle. java:378)
    at java.util.ResourceBundle.getObject(ResourceBundle. java:381)
    at java.util.ResourceBundle.getStringArray(ResourceBu ndle.java:361)
    at sun.util.TimeZoneNameUtility.retrieveDisplayNames( TimeZoneNameUtility.java:100)
    at sun.util.TimeZoneNameUtility.retrieveDisplayNames( TimeZoneNameUtility.java:81)
    at java.util.TimeZone.getDisplayNames(TimeZone.java:3 99)
    at java.util.TimeZone.getDisplayName(TimeZone.java:35 0)
    at java.text.SimpleDateFormat.subFormat(SimpleDateFor mat.java:1092)
    at java.text.SimpleDateFormat.format(SimpleDateFormat .java:881)
    at java.text.SimpleDateFormat.format(SimpleDateFormat .java:851)
    at java.text.DateFormat.format(DateFormat.java:316)
    at org.apache.tomcat.util.http.FastHttpDateFormat.get CurrentDate(FastHttpDateFormat.java:110)
    at org.apache.coyote.http11.Http11Processor.prepareRe sponse(Http11Processor.java:1596)
    at org.apache.coyote.http11.Http11Processor.action(Ht tp11Processor.java:968)
    at org.apache.coyote.Response.action(Response.java:18 3)
    at org.apache.coyote.Response.sendHeaders(Response.ja va:379)
    at org.apache.catalina.connector.OutputBuffer.doFlush (OutputBuffer.java:317)
    at org.apache.catalina.connector.OutputBuffer.close(O utputBuffer.java:278)
    at org.apache.catalina.connector.Response.finishRespo nse(Response.java:484)
    at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:177)
    at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:875)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11 ConnectionHandler.processConnection(Http11BaseProt ocol.java:665)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.process Socket(PoolTcpEndpoint.java:528)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThr ead.runIt(LeaderFollowerWorkerThread.java:81)
    at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:689)
    at java.lang.Thread.run(Thread.java:619)

  10. #10
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    Quote Originally Posted by babyboban View Post
    this is the code, which, showing the exception,

    ...
    What makes you think that is the code throwing the exception?

  11. #11
    babyboban is offline Member
    Join Date
    Jan 2010
    Posts
    7
    Rep Power
    0

    Default

    if the for loop iterating more than 90,000, thn it shows the above exception..

  12. #12
    babyboban is offline Member
    Join Date
    Jan 2010
    Posts
    7
    Rep Power
    0

    Default

    is it any problem regarding, HibernateSession...

    session.flush();
    session.clear();

    is it properly working or not..?

  13. #13
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,945
    Rep Power
    19

    Default

    Even if that is where the exception is thrown, there is no guarantee (at all) that that is the place where the problem actually lies. That's just where the JVM finally choked.

    The best way of tracking a memory leak problem (assuming you have given the JVM sufficient memory for the task in the first place) is to take a heap dump and stick it in an analyser. Sometimes you can hazard a guess as to the cause without doing this, but it's often luck. Analysing is the fastest way, in my opinion.

  14. #14
    babyboban is offline Member
    Join Date
    Jan 2010
    Posts
    7
    Rep Power
    0

    Default

    Hi,
    I have replaced the HibernateSession, instead of native JDBC quires. Tehn its working normally, without exception..!!!!!
    I am suspecton, is it any problem regarding, HibernateSession...?

  15. #15
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,945
    Rep Power
    19

    Default

    The only time I've had a problem with Hibernate and OOM exceptions is in a system where, as it eventually turned out, they weren't binding their queries, merely concatenating them, and hibernate's query cache simply overflowed.

  16. #16
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    What I'm hearing is that you are creating over 90,000 "saves" in one Hibernate transaction. No wonder the heap runs out of memory. Hibernate has to keep track of all that. Try adding a second, inner, loop. At the beginning of the loop, start a transaction. Form the inner loop so that each transaction handles no more than 1,000 "saves" before committing. That will give Hibernate a chance to free resources. GC should handle the rest, although adding a call to GC might not hurt.

  17. #17
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,945
    Rep Power
    19

    Default

    Well spotted.
    This is why I hate unformatted code...I scanned through that and thought they were committing every so often in that loop. But it's not comitted until right at the end.

  18. #18
    babyboban is offline Member
    Join Date
    Jan 2010
    Posts
    7
    Rep Power
    0

    Default

    Tolls, thx for ur valuable suggestions

  19. #19
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,945
    Rep Power
    19

Similar Threads

  1. Java heap space - OutOfMemory
    By iMemory in forum Java Applets
    Replies: 3
    Last Post: 10-13-2009, 09:51 PM
  2. Java heap space OutofMemoryError
    By everlast88az in forum Advanced Java
    Replies: 3
    Last Post: 05-18-2009, 08:12 AM
  3. Java Heap Space
    By sandeeprao.techno in forum Advanced Java
    Replies: 19
    Last Post: 10-30-2008, 11:27 AM
  4. Java heap space error
    By gezzel in forum New To Java
    Replies: 19
    Last Post: 09-25-2008, 12:07 AM
  5. Java heap space?
    By javanewbie in forum New To Java
    Replies: 1
    Last Post: 06-24-2008, 06:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •