Monitoring the JVM server in CICS with IBM Support Assistant

Memory leaks in Java programs can be as critical as they are in programs written in other languages. While Java has a Garbage Collector, it sometimes cannot remove objects because they are still referenced. Therefore memory leaks require you to first, locate them, and second, identify the class responsible. This article uses a sample Java program running in the CICS JVM server to show you how to locate a memory leak and identify the class responsible.

Share:

Adam Rice (adamrice@uk.ibm.com), Software Developer, IBM

Photo of Adam RiceAdam Rice is a System Tester on the CICS TS team at the IBM Software Lab in Hursley, United Kingdom. He has two years experience testing CICS, in which time his main focus has been Java within CICS. He has also worked on the CICS Dynamic Scripting Feature Pack and the CICS Deployment Assistant. You can contact Adam at adamrice@uk.ibm.com.



13 March 2013

Introduction

One of the advantages of using Java® is that memory management is easier, because you can simply create objects and let the Garbage Collector (GC) reuse the memory when they are no longer needed. Even with the GC, however, memory leaks can still occur in Java programs when references to objects are retained. This situation might arise when a program creates references to objects without ever removing them. One example is the use of a collection to which objects are added for processing, but never removed after storage and processing, which means that the application builds an ever-growing number of references to objects it no longer needs.

Typical heap usage remains constant over time after a program has finished starting up. Heap usage grows as more objects are created and more space on the heap is used. The GC can run and reclaim space occupied by objects that are no longer needed. When a Java program is leaking memory, heap usage grows, because objects are created that the GC cannot clean up, eventually causing a java.lang.OutOfMemoryError.

This article uses a sample Java program with an intentional memory leak running in the IBM® CICS® JVM server to show you how to use two tools in the IBM Support Assistant (ISA).

Introduction to ISA

ISA is a free client-side support and serviceability tool for all IBM software users. In addition, it provides a workbench for hosting other tools to assist with problem determination. Download ISA and find out more about it.

After you download ISA, you can customize the ISA Workbench with a wide variety of tools depending on your needs. This article focuses on two of the tools -- the Health Center and the Memory Analyzer. To add these two tools, go to the ISA Workbench homepage and click Analyze problem button, then click Find new tool add-ons link, and then check the boxes next to:

  • IBM Monitoring and Diagnostic Tools for Java -- Health Center
  • IBM Monitoring and Diagnostic Tools for Java – Memory Analyzer

Follow the installation wizard and restart ISA when prompted.

Connecting the Health Center

To get started, you need to modify the JVM profile for the JVM server. Add the -XhealthCenter option to the profile, disable it, and then enable the JVM server resource to register the changes.

The Health Center agent listens on a specific port. To find the port, look in the dfhjvmerr file for your JVM server, which is located in the directory specified by the WORK_DIR option in the JVM profile. Look for the following line to indicate which port you should connect to:

INFO: Health Center agent started on port 1972.

To connect the Health Center, launch ISA and click Analyze Problem on the homepage. From the list of installed tools, select the Health Center, follow the wizard, and enter the host name and port when required. After completing the wizard, the Health Center connects to your JVM server and begins to collect monitoring data.

Monitoring the JVM

After ISA has initialized, the links on the Status tab become active. Each link displays information related to a different perspective of the JVM that is useful in different situations. This article focuses on the GC perspective to show you how to used it to diagnose a memory leak. Click on the GC link to display a tab showing current heap usage in the JVM server.

In this example, the Health Center has been connected to a JVM server in which the sample program containing a memory leak is running. The chart shows that heap usage is increasing over time, as the GC cannot remove all of the objects that are being created:

Figure 1. Heap usage increasing over time
A chart showing heap usage in a JVM server increasing over time

It is important to observe the memory use increasing over time because a java.lang.OutOfMemoryError could also be caused by a Java program that requires more memory than the JVM has allocated for its maximum heap size.

Requesting a heap dump

To identify the objects that are using up the heap space, you can do a heap dump from the JVM, which contains data about all objects on the heap. To request a heap dump:

Recommended heap dump location

Place the heap dump in a folder located at the root level on your workstation. The process of analyzing the heap dump creates several files, and the root location will make it easier for you to navigate to them in the Heap Analyzer.

  1. From the Monitored JVM menu, select Request a dump.
  2. From the dialog box, select Heap dump.
  3. Click Finish.
  4. Remember the location of the dump.
  5. Using Binary mode, copy the dump to your local machine for analysis using FTP.

When the dump is stored on your local machine, you can use the Heap Analyzer to determine which classes are responsible for the usage.

Analyzing the heap dump

To analyze the contents of the heap dump, return to the ISA Home tab or the Analyze Problem tab and launch the Memory Analyzer. Then provide the location of the dump on the Remote Artifact Browse tab. After you select the heap dump, you can choose what kind of report to generate.

The report used here is the default Leak Suspects report, which includes a pie chart showing the objects responsible for using the largest portions of the heap. These objects are often a good place to start looking for the source of the problem. The report below shows that almost 75% of the heap is being used by a single instance of the com.ibm.cics.dw.example.TaskManager class:

Figure 2. A chart showing the classes suspected of leaking memory
A chart showing the classes suspected of leaking memory

Click on Details to get more information about how the memory in that instance has been used. You can use this information to resolve the issue and locate the source of the defect. After a fix has been applied to the application, you can repeat the same steps to monitor the JVM and ensure that the heap usage remains fairly constant over time.

Conclusion

This article used a Java application in CICS to demonstrate some of the information that ISA can provide. The Health Center offers a wealth of information about a JVM, beyond simply monitoring heap usage. Finding memory leaks can be time-consuming without the correct tools. ISA is a valuable tool for problem determination in Java applications, and can significantly reduce time and effort in tracking down defects.

Resources

  • CICS resources
  • IBM Support Assistant (ISA) resources
    • Download IBM Support Assistant
      Includes complete ISA product information and a quick video guide to ISA.
    • ISA forum
      Use this forum to discuss topics related to ISA, including installation, using ISA for troubleshooting, using support tools through ISA, collecting troubleshooting data, and ISA features and enhancements. Post ISA questions and comments, and share your ISA ideas and solutions with other users.
  • WebSphere resources
    • developerWorks WebSphere developer resources
      Technical information and resources for developers who use WebSphere products. developerWorks WebSphere provides product downloads, how-to information, support resources, and a free technical library of more than 2000 technical articles, tutorials, best practices, IBM Redbooks, and online product manuals.
    • developerWorks WebSphere application integration developer resources
      How-to articles, downloads, tutorials, education, product info, and other resources to help you build WebSphere application integration and business integration solutions.
    • Most popular WebSphere trial downloads
      No-charge trial downloads for key WebSphere products.
    • WebSphere forums
      Product-specific forums where you can get answers to your technical questions and share your expertise with other WebSphere users.
    • WebSphere on-demand demos
      Download and watch these self-running demos, and learn how WebSphere products and technologies can help your company respond to the rapidly changing and increasingly complex business environment.
    • WebSphere-related articles on developerWorks
      Over 3000 edited and categorized articles on WebSphere and related technologies by top practitioners and consultants inside and outside IBM. Search for what you need.
    • developerWorks WebSphere weekly newsletter
      The developerWorks newsletter gives you the latest articles and information only on those topics that interest you. In addition to WebSphere, you can select from Java, Linux, Open source, Rational, SOA, Web services, and other topics. Subscribe now and design your custom mailing.
    • WebSphere-related books from IBM Press
      Convenient online ordering through Barnes & Noble.
    • WebSphere-related events
      Conferences, trade shows, Webcasts, and other events around the world of interest to WebSphere developers.
  • developerWorks resources
    • Trial downloads for IBM software products
      No-charge trial downloads for selected IBM® DB2®, Lotus®, Rational®, Tivoli®, and WebSphere® products.
    • developerWorks business process management developer resources
      BPM how-to articles, downloads, tutorials, education, product info, and other resources to help you model, assemble, deploy, and manage business processes.
    • developerWorks blogs
      Join a conversation with developerWorks users and authors, and IBM editors and developers.
    • developerWorks tech briefings
      Free technical sessions by IBM experts to accelerate your learning curve and help you succeed in your most challenging software projects. Sessions range from one-hour virtual briefings to half-day and full-day live sessions in cities worldwide.
    • developerWorks podcasts
      Listen to interesting and offbeat interviews and discussions with software innovators.
    • developerWorks on Twitter
      Check out recent Twitter messages and URLs.
    • IBM Education Assistant
      A collection of multimedia educational modules that will help you better understand IBM software products and use them more effectively to meet your business requirements.

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into WebSphere on developerWorks


static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=WebSphere
ArticleID=861538
ArticleTitle=Monitoring the JVM server in CICS with IBM Support Assistant
publish-date=03132013