X Platform Knowledge Base

Skip to end of metadata
Go to start of metadata

 

Problem

This page provides tips for tracking down errors related to reference counting issues and pooling such as:

  1. java.lang.IllegalStateException: attempt to acquire an already disposed ...

    The above exception is indicating that MyHandler is trying to acquire a reference to MyEntity after it has already been disposed which it might do if it wants to ensure that it can keep a reference to it in its application state. Attempting to acquire a disposed reference is Illegal and indicative of a coding error because if MyEntity had been disposed and returned to a backing pool its contents would have been cleared, and it would be made available (possibly to another thread) for its own use. This is typically the result of a coding error in which wither:

    1. MyEntity was not acquired earlier in the code when it should have been and is thus a stale instance when referenced by MyHandler.

    2. Another thread has erroneously disposed of the MyEntity when it shouldn't have.
    3. MyHandler is erroneously calling acquire due to a programming error. 

  2. java.lang.IllegalStateException: attempt to dispose an already disposed ...

The above exception is indicating that when processing an acknowledgement ack and disposing of the MyMessage, the platform thread has found that reference to the embedded MyEntity has already been disposed out from under it. This indicates that some other thread has prematurely disposed of the MyEntity object when it shouldn't have. Allowing the acknowledging thread to dispose it would mean that it is possible that another thread could simultaneously pull the disposed MyEntity out of its backing pool, and the act of the acknowldeger disposing it would crear the revived entities contents out from under the other thread. Possible causes are:

    1. MyEntity was disposed twice by an application thread when it shouldn't have been. 

    2. MyEntity was disposed by a platform thread when it shouldn't have been (a platform bug)

Troubleshooting Steps

Reference tracking errors can be difficult to track down as reference counted objects may be passed between many threads and acquired and disposed at many different places in the code. To assist in tracking down reference counting issues, reference tracking can be enabled in the platform. When reference tracking is enabled, the platform will record calls to acquire() and dispose() for objects so that the information can be dumped if there is a reference counting error. 

Enabling Reference Tracking

Enabling reference tracking is very expensive, and should only be done in a troubleshooting context. It should never be enabled in production, and is not even a good idea to enable in qa environments as it can significantly change timing conditions for an application.

Reference tracking needs to be enabled at startup, it cannot be enabled dynamically at runtime. If you have enabled the reference tracking properly you should see "REFERENCE TRACKING IS ENABLED" or "REFERENCE TRACKING IS ENABLED FOR: [type1, type2]" printed to System.err at startup.

To enable reference tracking set the 'nv.reftracking.types' configuration property.

Via System Properties

To enable reference tracking for a specific type or types you may specify an '|' separated list of fully qualified types for which to enable reference tracking. 

Via XML Configuration Descriptor


Output

 

The above output shows a hypothetical platform bug in which the clearFieldReferences Method is disposing of an embedded entity field twice. 

There is no content with the specified labels