1

In my server, I have total 16GB memory. JVM max memory(Xmx)is assigned to 12GB. In JVM, we are running WSO2 ESB. We had set MaxMetaspaceSize=1g in JVM. That frequently gave us the following error.

java.lang.OutOfMemoryError: Metaspace

Then we removed the MaxMetaspaceSize=1g parameter from JVM. Then we came up the following two errors in JVM and we experienced slowness in the application as well.

Caused by: java.lang.OutOfMemoryError: Java heap space
Caused by: java.lang.OutOfMemoryError: Required array size too large

What can be a possible solution to get rid of initial Metaspace error?

Pradeep Sanjeewa
  • 636
  • 5
  • 18
  • It souds like there is something else going on. Checkout the top answer of https://stackoverflow.com/questions/37335/how-to-deal-with-java-lang-outofmemoryerror-java-heap-space-error for some tips on solving OOM issues. Good luck! – Scott Apr 01 '20 at 05:34
  • It's very likely there is a class loader leak in the application. It's not usual for a Java application to occupy 1GB metaspace. – apangin Apr 01 '20 at 08:16
  • Pradeep, the title sounds like there was no issue before and, suddenly without the parameter, you get OOM - could you please edit it? That's said, you should have a look at the memory occupied by your java process. You didn't say what JDK version you're using, but `jcmd GC.heap_info` is a good one to get a quick info; `jcmd VM.info` is a lot more verbose and quite useful too. Since JDK 11 (I think) there's also `jcmd VM.metaspace`. – Juraj Martinka Apr 01 '20 at 09:49
  • It is difficult to give a solution to this issue without looking at the operations you are doing inside the ESB. Are you using any high resource consuming mediators like Script mediators? – Arunan Sugunakumar Apr 01 '20 at 19:25
  • Hi Juraj: Edited the topic. Hope now it is more appropriate. Arunan: Yes there are script mediators as well as Class mediators – Pradeep Sanjeewa Apr 08 '20 at 07:08
  • So it looks you've always had memory issues in your app; with MaxMetaspaceSize a different error manifested first. So I wouldn't bother with limiting the Metaspace initially and try to fix the other OOM(s) first - here's anther question dealing with the "Required array size too large" issue: https://stackoverflow.com/questions/31382531/why-i-cant-create-an-array-with-large-size – Juraj Martinka Apr 21 '20 at 04:15

1 Answers1

-3

Follow below steps:

  1. Open catalina.sh from tomcat/bin.

  2. Change JAVA_OPTS to

    JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms1536m 
    -Xmx1536m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m 
    -XX:MaxPermSize=256m -XX:+DisableExplicitGC"
    
  3. Restart your tomcat

HK2
  • 17
  • 1
  • 5