Class ManagedObjectsFinalizer


@Singleton public class ManagedObjectsFinalizer extends Object
Invokes PreDestroy methods on all registered objects, when the injection manager is shut down.

Some objects managed by Jersey are created using InjectionManager.createAndInitialize(java.lang.Class<T>). This means that such objects are created, dependencies injected and methods annotated with PostConstruct invoked. Therefore methods annotated with PreDestroy should be invoked on such objects too, when they are destroyed.

This service invokes PreDestroy on all registered objects when InjectionManager.shutdown() is invoked on the injection manager where this service is registered. Therefore only classes with their lifecycle linked to the injection manager that created them should be registered here.

Petr Janouch
  • Constructor Details

    • ManagedObjectsFinalizer

      public ManagedObjectsFinalizer(org.glassfish.jersey.internal.inject.InjectionManager injectionManager)
      Creates a new instance of ManagedObjectsFinalizer.
      injectionManager - injection manager call preDestroy on managed objects.
  • Method Details

    • registerForPreDestroyCall

      public void registerForPreDestroyCall(Object object)
      Register an object for invocation of its PreDestroy method. It will be invoked when the injection manager is shut down.
      object - an object to be registered.
    • preDestroy

      @PreDestroy public void preDestroy()