I have a java heap space problem with hibernate since I add a modification in mi code. The program load information from a text file (2GB)
BufferedReader input = new BufferedReader(new FileReader(file));
while (line.compareTo(EOF) != 0) {
//Load of infoObject, lots of parse information from the text file
//Read lines of text using: line = input.readLine();
getSession().save(infoObject);
counter++;
if (counter % 100 == 0) {
getSession().flush();
System.gc();
}
}
This work great, now in case that the infoObject already exists in my db, I need to update the record, I use this:
BufferedReader input = new BufferedReader(new FileReader(file));
while (line.compareTo(EOF) != 0) {
//Load of infoObject
iObject infoObject_tmp = new iObject();
infoObject_tmp.setNumAccount(numAccount);
infoObject_tmp.setCloseDate(new Date("02/24/2011"));
iObject infoObject_search = (iObject) getSession().load(iObject.class, infoObject_tmp);
if (infoObject_search !=null){
getSession().update(infoObject);
}else{
getSession().save(infoObject);
}
counter++;
if (counter % 100 == 0) {
getSession().flush();
System.gc();
}
}
FreeMemory:
- Registry 1: 750283136.
- Registry 10000: 648229608.
- Registry 50000: 411171048.
- Registry 100000: Java Heap Space.
How can i fix the java heap space problem? I know that the problem is when i check if the iObject exists or not.