简体   繁体   中英

Java Heap size Memory

I have a Java application, which is throwing Java Heap size Memory error. My application is about converting a file into .csv format and load it into DB. When the File content is less my application is working good. But when i have hundreds of thousands of records i am getting heap size memory. What all possibilities for memory leak to happen when using classes like InputStream, OutputStream, BufferedWriter etc., Please help me to resolve this Heap size memory error. I am stuck with it for a week. Given below is the Heap size error i get

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

So, you're reading the whole file into the memory and then flush it to DB.

Instead of doing that you need to read chunks of file into memory and flush them into DB.

It's impossible to give a more detailed answer without the code.

when you run the file you need to add -Xmx## to the command line.

java -Xmx4G

would give you a JVM with 4 Gb available.

EDIT: if possible you should load one bit at a time like @Oleg mentioned.

I suggest you to increase heap size , you can use java -Xmx2048m in command line.

you will have up to 2GB memory now.

Follow this link for more

You can increase the heap size.

If you can share your code, i could tell you in what ways you can reduce the resource utilization

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM