Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.lang.OutOfMemoryError

 
Brian Smith
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Folks,
I would appreciate if you could provide some suggestion with regard to this problem here. I am trying to read a file that is 500 MB and put in StringBuffere and then put in a database. I would like to read the file into stringbuffer so that i don't have to make a multiple trips reading a line of that file and putting it into the database. but reading the whole file into buffer is giving "java.lang.OutOfMemoryError" error. do you guys have any suggestion on how i can achieve this? Also, the file could be even bigger than 500 MB.
Thanks.
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
first thing is to increase the size of the heap that Java is using. If the file itself is 500MB, then the JVM is going to need more room than that to work with the file and do other stuff.... so, check out the heap commands:



particularly look at -Xmx and -Xms

If you know you're gonna use at least 500MB, maybe you should initialize your heap to 512MB, with a max size of 1024MB?

so your command would look like:
java -Xms512m -Xmx1024m someClass
 
Clivant Yeo
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about just reading the data line by line from the file and enter them into the database on the fly without having to use the buffer?

Regards,
Clivant
[ January 19, 2005: Message edited by: Clivant Yeo ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic