Package com.day.util

Class FinalizerHandler


  • public class FinalizerHandler
    extends java.lang.Object
    The FinalizerHandler class implements the functionality to register Finalizers and call them at some point in time, such as the end of the current ExecutionContext.

    The registered Finalizers will be called in the reverse sequence of their registration. That is the last Finalizer registered will get called first.

    Since:
    antbear Audience dev
    • Constructor Detail

      • FinalizerHandler

        public FinalizerHandler()
    • Method Detail

      • registerObject

        public void registerObject​(Finalizer object)
        Registers a Finalizer.
        Parameters:
        object - the finalzier to register
      • unregister

        public void unregister​(Finalizer object)
        Unregisters a Finalizer object. After unregistering the objects doFinalize() method is not called anymore.
        Parameters:
        object - The Finalizer object to unregister.
      • unregisterAll

        public void unregisterAll()
        Unregisters all registered Finalizer objects so that a subsequent call to callFinalizers() effectively does nothing.
      • isEmpty

        public boolean isEmpty()
        Returns true if no Finalizer objects are registered yet.
        Returns:
        whether it's empty
      • callFinalizers

        public void callFinalizers()
        Calls all registered Finalizer Finalizer.doFinalize() method, and removes them from the internal list.

        The call to the Finalizer.doFinalize() is not expected to throw any exceptions or even errors. In case a Throwable is thrown this is logged as an error and processing continiues with the next Finalizer to be finalized.