Vinay
Vinay

Reputation: 347

about out of memory Exception

I have used Thread Pool for New IO server design . I have used newFixedThreadPool as a Executors factory method for thread pool creation. My server is throwing Exception when i execute my server for 20 to 30 minute . how to handle this exception.

java.lang.OutOfMemoryError: Java heap space

Upvotes: 0

Views: 2503

Answers (3)

Roger Lindsjö
Roger Lindsjö

Reputation: 11543

Obviously you are using too much memory, so now you need to find out why. Without your source it is very hard to to say what is wrong, but even with source it can be problematic when the program start to become complex.

What I have found helpful is to take memory dumps and look at them in tools such as Memory Analyzer (MAT). It can even compare several dumps to see what kind of objects are allocated. When you get an idea of what objects exists which you don't think should be there you can use the tool to see what roots it has (which objects has a reference to it).

To get a memory dump form a running java program use jmap -dump:format=b,file=heap.bin and to automatically get a memory dump when your program gets and OutOfMemoryError you can run it with java -XX:+HeapDumpOnOutOfMemoryError failing.java.Program

Upvotes: 1

Abhishek Choudhary
Abhishek Choudhary

Reputation: 8385

normally its java -Xms5m -Xmx15m MyApp -Xms set initial Java heap size -Xmx set maximum Java heap size

and in eclipse under java run configuration as VM argument -Xms128m

-Xmx512m

-XX:permSize=128M

-XX:MaxPermSize=384M

Upvotes: 0

gmhk
gmhk

Reputation: 15940

You can defnitely try increasing the HEAP SIZE and check if you are getting the issue.

However, I would prefer you to try profiling your application to find out why your heap size and where the memory is being consumed. There are few Profilers available as open source you can try.

Upvotes: 0

Related Questions