Caused by: java.lang.OutOfMemoryError: Java heap space

大兔子大兔子 提交于 2019-12-03 17:28:30
Jean Logeart

This error means that your program needs more memory than your JVM allowed it to use!

Therefore you pretty much have two options:

  1. Increase the default memory your program is allowed to use using the -Xmx option (for instance for 1024 MB: -Xmx1024m)
  2. Modify your program so that it needs less memory, using less big data structures and getting rid of objects that are not any more used at some point in your program

As Peter Lawrey pointed out, using a profiler to see what your program is doing in such situations is generally a good idea.

Use a producer/consumer pattern with a limited number of worker threads.

100+ threads is ridiculous - no wonder your application is exploding.

You haven't provided any information which indicates the problem is very different to all the answers given in StackOverflow regarding this error either;

  • You are using too much memory and you need to use a memory profiler to reduce it.
  • You are setting the maximum memory too low and you need to increase the maximum memory with -mx or -Xmx

I suspect that since you want 1000 users to run processes which take an hour each you may need more resources than you have. e.g. 1000 cores perhaps? I suggest you look at how much hardware you need based on the CPU, memory, disk IO and network IO that is required to run the users at an acceptible level e.g. 20 users and multiple that by 50.

You can try increasing the JVM heap space when you launch your application. You can try setting it to 2GB with -Xmx2g. If you're running 32-bit Java I think 2GB is as high as you can go, but if you have a 64-bit JVM you should be able to go higher.

Edit:

Example: java -Xmx2g MyApp

I will check 2 areas when there is out of memory error

  1. Is the allocated memory to the JVM sufficient, if not increase it using -Xmx
  2. Check the code thoroughly, more than 90% of the time I found the error with some loop going recursive under some border condition.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!