user1929839
user1929839

Reputation: 9

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

Upvotes: 0

Views: 396

Answers (4)

Madhura
Madhura

Reputation: 589

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

Upvotes: 0

Oleg Mikheev
Oleg Mikheev

Reputation: 17444

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.

Upvotes: 4

Ruchira Gayan Ranaweera
Ruchira Gayan Ranaweera

Reputation: 35587

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

Upvotes: 0

aplassard
aplassard

Reputation: 759

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.

Upvotes: 1

Related Questions