Results 1 to 19 of 19
Thread: Java heap space,
- 01-01-2010, 07:16 AM #1
Member
- Join Date
- Jan 2010
- Posts
- 7
- Rep Power
- 0
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
- 01-01-2010, 01:12 PM #2
Senior Member
- Join Date
- Aug 2008
- Posts
- 384
- Rep Power
- 5
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 -xmsI die a little on the inside...
Every time I get shot.
- 01-02-2010, 07:48 PM #3
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.
- 01-02-2010, 08:03 PM #4
Member
- Join Date
- Jan 2010
- Posts
- 9
- Rep Power
- 0
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.
- 01-02-2010, 08:05 PM #5
Just to chime in, 128M is pretty small for a Web app server. Try 512M...
- 01-02-2010, 09:54 PM #6
Or you can flush the memory when you come across with OutOfMemoryError :
I use it very oftenJava 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()); } }
- 01-05-2010, 07:13 AM #7
Member
- Join Date
- Jan 2010
- Posts
- 7
- Rep Power
- 0
thx, for all of your valuable comments, about the issue
- 01-05-2010, 07:17 AM #8
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
- 01-05-2010, 07:18 AM #9
Member
- Join Date
- Jan 2010
- Posts
- 7
- Rep Power
- 0
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)
- 01-05-2010, 07:33 AM #10
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
- 01-05-2010, 08:44 AM #11
Member
- Join Date
- Jan 2010
- Posts
- 7
- Rep Power
- 0
if the for loop iterating more than 90,000, thn it shows the above exception..
- 01-05-2010, 08:49 AM #12
Member
- Join Date
- Jan 2010
- Posts
- 7
- Rep Power
- 0
is it any problem regarding, HibernateSession...
session.flush();
session.clear();
is it properly working or not..?
- 01-05-2010, 11:25 AM #13
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
- 01-13-2010, 11:48 AM #14
Member
- Join Date
- Jan 2010
- Posts
- 7
- Rep Power
- 0
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...?
- 01-13-2010, 12:55 PM #15
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
- 01-14-2010, 01:26 AM #16
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.
- 01-14-2010, 08:55 AM #17
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
- 01-14-2010, 12:00 PM #18
Member
- Join Date
- Jan 2010
- Posts
- 7
- Rep Power
- 0
Tolls, thx for ur valuable suggestions
- 01-14-2010, 12:22 PM #19
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Similar Threads
-
Java heap space - OutOfMemory
By iMemory in forum Java AppletsReplies: 3Last Post: 10-13-2009, 09:51 PM -
Java heap space OutofMemoryError
By everlast88az in forum Advanced JavaReplies: 3Last Post: 05-18-2009, 08:12 AM -
Java Heap Space
By sandeeprao.techno in forum Advanced JavaReplies: 19Last Post: 10-30-2008, 11:27 AM -
Java heap space error
By gezzel in forum New To JavaReplies: 19Last Post: 09-25-2008, 12:07 AM -
Java heap space?
By javanewbie in forum New To JavaReplies: 1Last Post: 06-24-2008, 06:55 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks