java run out of memory issue

前端 未结 6 2154
自闭症患者
自闭症患者 2021-01-04 13:13

I have a jar file running on an amazon-ec2-m1.large instance with linux 64bit operating system. I run out of memory after different hours, usually between 2-4, although in m

相关标签:
6条回答
  • 2021-01-04 13:25

    Please try 64 bit version of Java if you are using 32 bit version,

    Also add new JVM argument , "-XX:+CMSClassUnloadingEnabled \ " which clear some unused class objects

    0 讨论(0)
  • 2021-01-04 13:39

    I was able to resolve an almost identical error by following the advice given by:

    https://confluence.csiro.au/pages/viewpage.action?pageId=278167841

    Essentially, they state:

    When the Java Virtual Machine starts, by default it spawns a number of Garbage Collection (GC) threads, which are used for parallel GC operations … the number of such threads is calculated by this formula: (ncpus <= 8) ? ncpus : 3 + ((ncpus * 5) / 8) … Because of the creation of these many threads … the program will automatically reach the system limit …

    I limited the number of garbage collecting threads using the environment variable, like so:

    export _JAVA_OPTIONS="-XX:ParallelGCThreads=2"
    

    Not sure about the overall performance hit regarding GC, but at least today's work is done.

    Please check the original post for more options.

    Good Luck, - Stu

    0 讨论(0)
  • 2021-01-04 13:44

    Heap is only part of the equation. Have a look at total resident memory - it includes heap and off heap contributions. Off heap includes mapped JARs, thread stacks (~1MB per thread), perm gen, etc. SO has a number of questions on how to do it on Linux.

    0 讨论(0)
  • 2021-01-04 13:46

    If you have more physical ram available use that . It seems that the heap size allocated is only 1656 mb which perhaps is not enough. Try running java jar file with two switches -xmx4096mb and -xms 2048 Then monitor the usage , perhaps the memory requirement is too large for your application , if you still run out of memory after sometime then it needs further investigation to check if your code is leaking memory. Hope this helps , let me know if you need more clarification

    0 讨论(0)
  • 2021-01-04 13:46

    Solved with the latest jdk. Please try installing java-11-openjdk

    0 讨论(0)
  • 2021-01-04 13:48

    Without trying to decode the dump data, I'll observe that there are basically three cases for running a JVM out of memory:

    1. Having a structure (list of lists or whatnot) that is allowed to accumulate masses of unused (but still referenced) data.
    2. Leaving various "handles" open -- file handles, threads, data base operations. Especially if using an API with a native component you can potentially leave a lot of stuff outside of the reach of GC.
    3. Making a single extremely large request (or a "burst" of such requests).

    Kind of in-between here would be classes. If you run a app that dynamically creates and loads classes, you must properly use individual class loaders to make the classes collectable.

    0 讨论(0)
提交回复
热议问题