• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting Java heap space error

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code snippet is like this:

Session session = HiberUtil.getSession();
String queryAmmend0 = "from com.hib.Phase1And2CisgiAmendIdBean " +" as obj where obj.processFlag ='Phase2'and obj.status = 'C' ORDER BY obj.invoiceNumber ASC ";
Query query=session.createQuery(queryAmmend0);
List<Phase1And2CisgiAmendIdBean> listAmmend0 =query.list();

Here the query is fetching more than 8 lakh records and when trying to add to the list(listAmmend0) the java heap space error is triggered......

Can anyone there help me out on this.Thanks in Advance!!!
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Set the following to increate the heap size
-Xms5M -Xmx1024M
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The -Xms5M will not be necessary, but it can help. The other one sets the maximum amount of memory Java can use (from 64MB) to 1024MB. Never forget the M though, or you will have only 1024 bytes!
 
Praveen Ramachandran
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am still getting the heap space after trying the fix you have mentioned ..Anywaz thanks for the effort!!
 
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are fetching 800K Record, and your driver load them into memory causing outofmemory Exception.

Try this, Use limit clause of sql, bring bunch by bunch

Or

more elegant solution,(Assuming your Database and its driver supports Scrolling, and also its better to use jdbc:mysql://localhost/semanticdb?useCursorFetch=true) Mysql 5.X supports Scrolling


 
reply
    Bookmark Topic Watch Topic
  • New Topic