Java Stack

SAP Java Stacks: How to solve Java OutOfMemory situations

SAP Java Stacks are quite unknown for people that works in the SAP world. I have to say that I’m not a big fan of SAP Java Stacks/Systems. Some simple tasks that are quite easy to do on ABAP systems get quite difficult and frustrating when working with JAVA systems. Despite of this if you work as a Basis Consultant it is mandatory to know about this type of systems. In this post I will show you how to investigate OutOfMemory (OOM) errors in SAP Java systems.

The problem

In this case the system having the issue was a SAP PO 7.4 running on a Java Stack. This means that there is no ABAP stack as usual in SAP PI/PO systems which run as a Dual Stack. In this case the OOM error caused that the server having the issue completely stopped after the error. If you take a look to the log files on the directory /usr/sap/SID/JXX/j2ee/cluster/serverX/log you would find an error message like this:

javax.ejb.EJBException: ASJ.ejb.005043 (Failed in component: sap.com/com.sap.xi.mdt2, BC-XI-IS-WKB) Exception raised from invocation of public 
java.util.ArrayList com.sap.aii.mdt.server.adapterframework.AdapterFrameworkMonitoringBean.getLogEntries(java.lang.String,java.lang.String) throws 
com.sap.aii.mdt.api.exceptions.OperationFailedException,java.lang.NumberFormatException,java.rmi.RemoteException method on bean instance 
com.sap.aii.mdt.server.adapterframework.adapterengine.AdapterFrameworkMonitoringBean@2946887a for bean 
sap.com/com.sap.xi.mdt2*xml|com_sap.xpi.mdt.afmetadata.jar*xml|AFMessageMonitoringBean in application sap.com/com.sap.xi.mdt2.; nested exception is: 
java.rmi.RemoteException: java.lang.OutOfMemoryError: Java heap space (failed to allocate 536870928 bytes) (max heap: 4096 MB)

The error message appears in the defaultTrace_00.XX.trc. It is also possible to see it in the log viewer inside the NWA:

OOM error message in SAP NWA Log Viewer

After restarting the server and even the SAP PO system the problem appeared again after a while.

The investigation

So the first thought you probably had when having this errors is to increase the memory parameters and see if it works, right? This is wrong and it will only cover the issue. I admit I did it a few times but it is better to spend some time investigating the issue than doing this workaround. When the Java Stack have a OOM error while working it generates a file named OOM.hprof inside the directory /usr/sap/SID/JXX/j2ee/cluster/serverX/log. The first thing you should do is to download this file to study it later. If you try to open this file with a text editor you will see nothing, fortunately Eclipse released a tool for analyzing this files.

Eclipse Memory Analyzer is a tool released by Eclipse as Open Source Project that allows to open OOM.hprof files and investigate inside them. These files shown the state of the memory inside the java server process before crashing. There is an excelled guide of how to work with this program but I’ll show you the basic steps.

  • Open the Eclipse Memory Analyzer and click File – Open Head Dump. Over there select the OOM.hprof file that you downloaded before.
  • Leave the first options selected:
Eclipse Memory Analyzer wizard for OOM.hprof file
  • The application will show the memory leak suspects:
Memory leak suspects
  • As you can see in this case the thread consuming 2,5GB is com.sap.engine.core… and the object address is 0x745513290.It is also important to see where the memory is accumulated. It appears in the following part:
Information about instance and class
  • The next step is to find this memory address inside the OOM.hprof to see what could be causing the memory leak. In the top part you have the option Find object by address:
Find object by address
  • A new screen opens where we can see some information related to the Class Name such as parent, package, resource, etc.

The solution

The next step is to look in the SAP Support Portal for SAP Notes with this class, check the SCN and Google. Please keep in mind that the instance could be the same one but the instance can change. In this case I look for the class and instance and I found the SAP Note 2217500 – PI OOM: AdapterMessageMonitoring Web Service that points to the SAP Note 1979364 – OOM when calling AdapterMessageMonitoring web service. Please keep in mind that the instance described in the first SAP Note is not the same as the one we have in the Eclipse Memory Analyzer but in my case the solution described worked perfectly and the issue was gone after updating the SAP System to the patch described.

In case you need to increase the heap memory as a workaround you can do it using the SAP Config Tool as described here.

5 / 5 ( 1 vote )
Mike

Recent Posts

DevOps, Infrastructure as Code and SAP

I hope you all survived the log4j Apocalypse and Christmas, hopefully you had a great…

2 years ago

Log4Shell Critical vulnerability

I know it is being a while since I posted the last time. So far…

2 years ago

Adobe Acrobat Reader Security Update causing issues with SAPGUI

UPDATE 11/25/2020 Adobe released a new patch that solves the issue a few days ago:…

3 years ago

SAP GUI 7.70 Preview: They will know me as Quartz

Good news for you fanatics of SAP GUI! SAP will release SAP GUI 7.70 in…

4 years ago

Preparing the SAP Cloud Consultant Interview

Quick update since I don't have a lot of time lately. During my 2019 job…

4 years ago

It's the final countdown (2019 Edition)

It's been a while since the last time I wrote an entry in my blog.…

4 years ago