Using Java Managed Beans to Manage and Monitor COBOL Applications

Java technology includes support for managing and monitoring applications, objects and devices. JVM COBOL provides a managed bean (MBean) that enables you to manage and monitor RunUnits.

To enable the RunUnit MBean

You can enable a RunUnit MBean in one of the following ways:

  • For a particular RunUnit level
  • For all RunUnits you create

Using the RunUnit class to enable the RunUnit MBean for a particular RunUnit level:

A constructor on the RunUnit includes a RunUnitStartupOptions enum with a new value called UseManagementBean. The following illustrates how you can use the RunUnitStartupOptions enum with its UseManagementBean option:

 RunUnit myRUBean = new RunUnit("MyApplication", 
                  RunUnitStartupOptions.UseManagementBean)
 try
 {
   myRUBean.add(new PROGRAM1());  // Where PROGRAM1 is the COBOL program
 } 
 finally
 {
    myRUBean.stopRun();
 }    

Using a cobconfig.properties text file to enable the MBean for all RunUnits you create:

  1. Use a text editor to create a file, cobconfig.properties.
  2. Add the following content to the file:
    mbeans=true
  3. Save the text file either in your application's .jar file or in the directory that stores your class files.

Using MBeans to identify issues

There are different programs such as Oracle's Java Mission Control or JConsole that enable you to view and use MBeans.

Before you can use the MBean with some versions of JRE, you need to enable your application for dynamic attachment. To do this, execute the following command from the Java command line:

-Dcom.sun.management.jmxremote

An MBean provides the following two attributes that enable a visual indication of how many RunUnits are live:

LogicalRunUnitCount
Provides a rolling counter of the numbers of RunUnits that have been created minus the number of RunUnits that have been ended.
LiveRunUnitCount
States the number of RunUnits that have not been garbage-collected.

If the values of LiveRunUnitCount and LogicalRunUnitCount, it could indicate one of the following issues:

  • One or more RunUnits have not been ended cleanly. You can end the RunUnit cleanly in one of the following ways:
    • Add an invoke to the StopRun method in the RunUnit class itself.
    • Add a STOP RUN call in the application. This automatically ends the RunUnit and causes a COBOLStopRunException.
  • If LiveRunUnitCount is larger than LogicalRunUnitCount, the RunUnit has most likely been kept alive because it is being held by another class. To resolve this, check where the RunUnit instance is stored and either set that instance to null or to end it, invoke the StopRun method in the RunUnit.
Note: There is always at least one RunUnit counter. This is because an initial or default RunUnit is created automatically for any application that does not use the RunUnit class.

The following figure shows an example of how the Java Mission Control tool displays a leak:

Figure 1. An example of a leak shown in Oracle's Java Mission Control Tool GUID-16BB632B-BCDE-4AD4-949D-F6C15531342F-low.png

Using MBeans to identify long-running RunUnits

You can use the MBean operation dumpAllLongRunninhRunUnitInfo to identify RunUnits that have been running for a specific period of time. The MBean operation takes a long parameter for the time in milliseconds.

In Oracle's Java Mission Control application, you can find this on the Operations tab for com.microfocus.runtimeservices and in the MBean Tree section - see the figure below.

Figure 2. Analysis of a long-running RunUnit in Oracle's Java Mission Control Tool Analysis of a long running RunUnit

The information returned from the MBean enables you to see the name, id, start time, GUID and a stack trace of where the RunUnit was created.

The oldest RunUnit is always the RunUnit with an id of 1 and this is the initial or default RunUnit.

Recommendation for best coding practice

If you create and use the RunUnit in the same method, Micro Focus recommends that you release the MBean in the finally clause - for example:

RunUnit myRUBean = new RunUnit("MyApplication", 
                  RunUnitStartupOptions.UseManagementBean)
 try
 {
    ... use the myRUBean object
 } 
 finally
 {
    myRUBean.stopRun();
 }        

For more information, see: