View Full Version : java.lang.OutOfMemoryError: Java heap space
frhead
Apr 21st, 2006, 04:22 PM
Hi, I am trying to implement the Spring MVC Framework.
I am using Tomcat as container.
So I am making some tests to understand the framework and see how I will integrate it into my project and from time to time I get this error:
org.springframework.web.util.NestedServletExceptio n: Handler processing failed; nested exception is java.lang.OutOfMemoryError: Java heap space
org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:836)
org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:727)
org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:396)
org.springframework.web.servlet.FrameworkServlet.d oGet(FrameworkServlet.java:350)
javax.servlet.http.HttpServlet.service(HttpServlet .java:689)
javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
I guess I understood it was because too many objects were instanciated. So the question is what do I do wrong?
I am using some beans declared in the xxx-servlet.xml and other java class.
Thanks in advance
Fred
gdub
Apr 21st, 2006, 07:33 PM
I was just dealing with this, although it was with the Jetty plugin for Maven rather than Tomcat. But the discussion on the Maven mailing list extended to Tomcat, too.
If your problem is the same one, it has to do with the automatic reloading of your app when changes are detected. So, my response is irrelevant if you're not doing that.
The short of it is that every time your container reloads your app in the same JVM, it creates new class loaders. For some voodoo reason, the class loaders can't be released. So after some number of reloads, you run out of the class of memory used for that purpose--at least that's where the Maven discussion ended up. Personally, I was able to increase so-called permanent memory and get more reloads per launch.
Relevant articles:
http://tomcat.apache.org/faq/deployment.html
http://raibledesigns.com/page/rd/20060419
-dub
bling683
Sep 5th, 2006, 09:40 AM
Are you by any chance using Hibernate along with Spring Framework? If this is so, you might want to consider taking a look at your hibernate mapping files. If you're using lazy-loading, you should set that to true so you don't have to load all the object at once. That could be a factor with memory. If you're not using hibernate, sorry for reading all of that :rolleyes:
Beans are singletons and stateless. You shouldn't be having memory problems in your config files nor any of the bean configurations. You might want to bump up your memory allocations if you're using Tomcat. That will allocate more heap space as well as memory depending on what your capacity on the machine or server.
Costin Leau
Sep 5th, 2006, 11:36 AM
search the forum for "heap space" and you'll find some related threads - there is an issue related to CGLIB on tomcat which prevents the webapps to be garbage collected - in time your whole memory is affected.
I'm not sure if Jetty is an answer since the problem seems to be at the way the VM/CGLib works. Until this moment, the only solution I know of is switching to JRockit :) - note that I haven't used this myself so I can't confirm it.
sajeev
May 14th, 2007, 07:47 AM
Hi,
I am working with Spring and hibernate.When i tried to get a large amount of datas from a database table, it is throwing the following error: java.lang.OutOfMemoryError: Java heap space...
If the amount of data is small it is working fine... If the datas are approximatly greater than 40000 ,it is thowing that error.
I am using HibernateCriteria for searching ..The coding is given below:
public List listDepositLogPaging(final String terminalId,final String startDate,final String endDate,final int pageNumber,final int pageSize){
HibernateCallback callback =new HibernateCallback(){
public Object doInHibernate(Session session)throws HibernateException{
Criteria criteria = session.createCriteria(CSPDepositLog.class)
.addOrder( Order.desc( "timeStamp" ));
if (!terminalId.equals("")) {
criteria.add(Expression.eq("merchant.terminalID", terminalId));
}
if ( !"".equals( startDate ) && "".equals(endDate) ) {
try{
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
Date d = formatter.parse(startDate);
System.out.println("Date-> "+d);
criteria.add(Expression.between("timeStamp", d,new Date()));
}
catch(Exception e){
e.printStackTrace() ;
}
}
if(!"".equals( startDate ) && !"".equals( endDate )){
try{
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
Date d = formatter.parse(startDate);
Date d1 = formatter.parse(endDate) ;
int date = d1.getDate() ;
d1.setDate(date+1);
System.out.println("Date1-> "+d);
System.out.println("Date1-> "+d1);
criteria.add(Expression.between("timeStamp", d, d1));
}
catch(Exception e){
e.printStackTrace() ;
}
}
criteria.setFirstResult( pageNumber ).setMaxResults( pageSize ) ;
List list = criteria.list();
System.out.println("LIST SIZE -> "+list.size());
return list;
}
};
return (List)getHibernateTemplate().executeFind(callback) ;
}
In the above code:
List list = criteria.list();
when the datas in the list exceeds around 40000 ,that error is throwing..
Anybody help me to solve this issue....
Thanks in Advance
Sajeev
Marten Deinum
May 14th, 2007, 08:46 AM
Implement some kind of paging. 40000 records will mean that 40000 instances of an object (and all it's references) are being created. When using Hibernate in combination with lazy loading, also 40000 proxies are being generated. All of this is memore consuming.
dr_pompeii
May 14th, 2007, 10:02 AM
hi mdeinum
can you share some links tutorials for this with hibernate,
but working with springmvc???
thanks for advanced
Marten Deinum
May 14th, 2007, 10:06 AM
Search the forums, the question has been answered multiple times. For Hibernate you might also want to check the reference guide.
sajeev
May 15th, 2007, 03:26 AM
Anybody knows how we will get the count using Hibernate Criteria...
Thanks in advance
Sajeev
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.