wood burning stoves 2.0*
The moose likes Java in General and the fly likes java.lang.OutOfMemoryError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "java.lang.OutOfMemoryError" Watch "java.lang.OutOfMemoryError" New topic
Author

java.lang.OutOfMemoryError

Brian Smith
Ranch Hand

Joined: Oct 26, 2002
Posts: 232
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

Joined: Oct 17, 2001
Posts: 4313

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


- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
Clivant Yeo
Ranch Hand

Joined: May 22, 2004
Posts: 124
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 ]

Clivant Yeo
My Personal Website
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.lang.OutOfMemoryError
 
Similar Threads
Parsing huge CSV file/ Time to load in the memory
JDBC QUERIES
JAVA HEAP SIZE and files to byte[]-Array
Creating spanned ZIP with Java?
File navigation and I/O