Use of MboSet DISCARDABLE Flag to Optimize JVM Garbage Collection: Caveats

Use of MboSet DISCARDABLE Flag to Optimize JVM Garbage Collection: Caveats

You may have come across a blog or article that discusses the use of the MboSet DISCARDABLE flag to facilitate faster JVM garbage collection when creating customizations (Automation Scripts, Java class extensions). The following code snippet illustrates how this flag is used during instantiation of an Inventory Mbo to set record editability by checking the user's storeroom authorization via a LocationSet:

MboSet locationSet = mbo.getMboSet("LOCATIONS");

locationSet.setFlag(MboConstants.DISCARDABLE, true);

Mbo loc = (LocationRemote)locSet.getMbo(0);

if (loc != null)

{

     //Code to check user authorization

}

locationSet.close();

This LocationSet does not need to be cached because the Location Mbo will not be saved, nor will it need to be accessed again during the Inventory Mbo’s instantiation. Additionally, the LocationSet does not have any child MboSets that need to be saved. This is an ideal situation for using the DISCARDABLE flag to insure that the memory used by this set is quickly released.

While this flag can be helpful for memory optimization while writing Maximo code, there are important caveats. The following is checklist of items to consider before using the DISCARDABLE flag to help avoid errors or unexpected behavior while using the DISCARDABLE flag:

  • DISCARDABLE MboSets are flagged as NOSAVE and will not be saved. The DISCARDABLE flag should only be used on MboSets that do not need to be saved or accessed again.
  • DISCARDABLE MboSets can only be traversed forward because the current Mbo is cleared from memory when the next Mbo is accessed. If a MboSet is used for traversing forward only and not to be saved, use DISCARDABLE MboSet.
  • DISCARDABLE MboSets still needs to be explicitly closed to realize the benefit of faster garbage collection/freeing of memory. Note in the above snippet how “locationSet.close();” is called when the set is no longer needed.
  • While child MboSets of DISCARDABLE MboSets do not inherit the DISCARDABLE flag, they are created as NOSAVE. Changes made to Mbos that are children of a DISCARDABLE MboSet will not be saved. However, this NOSAVE flag on MboSets that are children of a DISCARDABLE MboSet can be reversed by explicitly calling MboSet.setFlag(MboConstants.NOSAVE,false). If you need to save a MboSet that is a child of a DISCARDABLE MboSet, call MboSet.setFlag(MboConstants.NOSAVE,false) on the child MboSet so that it can be saved.
  • The DISCARDABLE flag itself cannot be reversed. Once a MboSet is DISCARDABLE, it will always be DISCARDABLE. If code attempts to change a MboSet from DISCARDABLE=true to DISCARDABLE=false, the following error will be logged:
    psdi.util.MXApplicationException: system#UnsetDiscardable
         at psdi.mbo.MboSet.setDiscardableFlag(MboSet.java:6844)
         at psdi.mbo.MboSet.setFlag(MboSet.java:6787)
    You may notice a lack of detail in this error message. That has been reported under APAR IJ43688. Starting with Manage 8.8, this error will include the following message:
    psdi.util.MXApplicationException: BMXAA10048E - The MboSet is flagged as DISCARDABLE. Once a MboSet has been flagged 
    as DISCARDABLE it cannot be reversed. The DISCARDABLE flag should only be used for MboSets for information purposes 
    because DISCARDABLE MboSets cannot be saved.
         at psdi.mbo.MboSet.setDiscardableFlag(MboSet.java:6844)
         at psdi.mbo.MboSet.setFlag(MboSet.java:6787)
To summarize, the DISCARDABLE flag should only be used for a MboSet when the code using that MboSet:

* Will never need to save any changes to that MboSet

* Will never need to save any changes to any child MboSets created from that MboSet unless you intend to explicitly call MboSet.setFlag(MboConstants.NOSAVE,false) on the child MboSets you want to save

* Will only need to traverse forward through the MboSet