Sun GlassFish Enterprise Server v3 Prelude Add-On Component Development Guide

HK2 Lifecycle Interfaces

Components can attach behaviors to their construction and destruction events by implementing the org.jvnet.hk2.component.PostConstruct interface, the org.jvnet.hk2.component.PreDestroy interface, or both. These are interfaces rather than annotations for performance reasons.

The PostConstruct interface defines a single method, postConstruct, which is called after a component has been initialized and all its dependencies have been injected.

The PreDestroy interface defines a single method, preDestroy, which is called just before a component is removed from the system.

Example 2–1 Example Implementation of PostContruct and PreDestroy

public class MyContainer implements Container, PostConstruct, PreDestroy {
	Logger logger;
	public void postConstruct() {"Starting up.");

	public void preDestroy() {"Shutting down.");