Garbage Collection

The OpenJMS server periodically runs a garbage collector to conserve memory. Garbage collection will also be run if available memory falls below a configured threshold.

The garbage collector collects:

  • Expired messages

    These are messages whose JMSExpiration property is non-zero, and the time indicated by the property has passed.

    Expired messages are removed both from memory and/or the database if they are persistent.

  • Message caches

    Messages are cached on a per-destination basis. A topic message cache will be garbage collected if it has no active consumers. A queue message cache will be garbage collected if it has no active consumers and:

    • it is administered and contains no messages; or
    • it is temporary, and there is no corresponding Connection instance (i.e, the client connection has been closed or lost)
    An active consumer is any TopicSubscriber, QueueReceiver or QueueBrowser currently registered with the message cache.

  • Cached persistent messages

    These are messages cached in memory to avoid the overhead reading them from the database. These are removed from memory when available memory is low.


The garbage collector is configured via the <GarbageCollectionConfiguration> element in the $OPENJMS_HOME/config/openjms.xml configuration file:

  <GarbageCollectionConfiguration memoryCheckInterval="30"

See Also

The following references provide detailed descriptions of the configuration elements related to garbage collection: