Singletons with EJB3.0 on JBoss 5.1

To create a singleton bean that can be injected into EJB:
– annotated the class with org.jboss.ejb3.annotation.Service
– let the class implement some Local or Remote interface.

Moreover, when you want to perform some setup upon singleton startup, you can:
– create an *MBean interface with void start()
– make singleton implement the interface
– add @Management([interface class]) annotation on singleton class

Example:

@Local
public interface SingletonExample{}
public interface SingletonExampleMBean {
    void start();
}
@Management(SingletonExampleMBean.class)
@Service
public class SingletonExampleImpl implements SingletonExample, SingletonExampleMBean {
    @Override
    public void start() {
        // some initialization stuff
    }
}

More info can be found in: JBoss reference

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s