• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

java.lang.outofmemoryerror: java heap space hibernate batch insert

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am trying to insert bulk records into a table, the following is code in my dao. I am using spring and hibernate

for(int i=0;i<allImportClients.size();i++){

ImportClients importClient = (ImportClients)allImportClients.get(i);
getHibernateTemplate().saveOrUpdate(importClient);
if ( i % 10 == 0 ) {
getHibernateTemplate().flush();
getHibernateTemplate().clear();
}
}

and my cfg.xml file has

<property name="hibernate.jdbc.batch_size">10</property>
<property name="hibernate.cache.use_second_level_cache">false</property>

This works fine when i am uploading 1200 records manually.
But when i try with loadrunner by creating 4 vusers who cocurrently insert 1200 records each, then it is throwing exception as

java.lang.outofmemoryerror: java heap space

Please, help me.
Thanks in advance
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is pretty much "what you see is what you get."

You're out of memory, either on your JVM, your computer, or both.

Is there any reason to believe it is something other than that? Let us know what you're thinking.

-Cameron McKenzie
 
kkalyan kkumar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for your reply.

I agree that the problem is with memory
But i wanted to know what I need to do to solve this........

Any suggestions will be really useful to me.

Thanks a lot in advance.
 
Cameron Wallace McKenzie
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, the first things that come to mind are potentially increasing the Java heap size, which can be done with JVM switches.

-Xmsinitial java heap size
-Xmxmaximum java heap size

You might also want to increase the amount of physical memory on the machine.

Maybe even distributing the load across several JVMs might help address the problems.

Nothing magical, unfortunately.

Good luck!

-Cameron McKenzie
 
kkalyan kkumar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey thanks for the help.

I am using spring-hibernate-maven-jetty project environment.
so, to increase the jvm size i have set

MAVEN_OPTS to -Xmx1024m.

Hope i am in the correct path.
Thanks for your timely help.
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by kkalyan kkumar:
Hey thanks for the help.

I am using spring-hibernate-maven-jetty project environment.
so, to increase the jvm size i have set

MAVEN_OPTS to -Xmx1024m.

Hope i am in the correct path.
Thanks for your timely help.



Hi Kalyan,

I believe you have an INI file at your maven path. INI file you would able to see the arguments as you mentioned above. Change your setting there. It will work.

~Ramesh.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by kkalyan kkumar:
Hey thanks for the help.

I am using spring-hibernate-maven-jetty project environment.
so, to increase the jvm size i have set

MAVEN_OPTS to -Xmx1024m.

Hope i am in the correct path.
Thanks for your timely help.



Um, Maven is your build technology, not running Java.

Unless it is while you are building that you do the bulk insert. And maybe even then you still want your "java" memory increase, so you would have to look in your pom.xml for the line that runs "java" and add it there. That is if it is when you build that it does the inserts.

If it is in your application, then you need to add that option to the line that calls "java" when you start up your application.

However, are you sure the code inside this if statement is ever called?

if ( i % 10 == 0 ) {
getHibernateTemplate().flush();
getHibernateTemplate().clear();
}

Because that should evict those objects and you shouldn't have a memory problem with Hibernate.

Mark
 
kkalyan kkumar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,

Thanks for really useful help
Ya, the if condition is executed and i am not getting the out of memory exception when i manually do bulk insert.

As posted in my first comment, the problem comes when i do bulk insert with
loadrunner........

anyway, now i am looking into loadrunner.

thanks a lot for the help
 
kkalyan kkumar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the bulk insert goes in my application when user triggers it by clicking an uploading a file with bulk data.

You said,

........
you need to add that option to the line that calls "java" when you start up your application.
.........

Hey Mark Spritzler, out of interest i am asking,
what does the above line means.........sorry, i did not understand it exactly.

can you please give some more pointers that helps me to understand it.

Thanks in advance
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, click, from where a Swing application, a website, or from some other app that calls out to java?

In a swing app, whatever starts your main class. From a website, probably be your server like when you start Tomcat or some app server. From some other app that calls out to java, then in that call. Wherever java is being called that loads your classes.

Mark
 
kkalyan kkumar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for the input
 
reply
    Bookmark Topic Watch Topic
  • New Topic