0

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
Vinay
  • 347
  • 1
  • 7
  • 16
  • It would help to see some actual code. Otherwise, any answer is just a guess. – Ken Wayne VanderLinde Mar 22 '12 at 03:56
  • 2
    Obviously, there is memory leak, and you can check here for related tools and discussions: http://stackoverflow.com/questions/40119/how-to-find-a-java-memory-leak http://stackoverflow.com/questions/1716597/java-memory-leak-detection-tools – Jerry Tian Mar 22 '12 at 03:58
  • If you haven't set it size is probably large enough unless you have a 32-bit windows PC. If you do, add the `-server` command line option. – Peter Lawrey Mar 22 '12 at 06:29

3 Answers3

1

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

Rich
  • 15,602
  • 15
  • 79
  • 126
Roger Lindsjö
  • 11,330
  • 1
  • 42
  • 53
0

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.

gmhk
  • 15,598
  • 27
  • 89
  • 112
0

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

Abhishek Choudhary
  • 8,255
  • 19
  • 69
  • 128