How to create a MDB 3.0 singleton ?

You can specify the maximum number of JMS Sessions that are available to concurrently deliver messages to an MDB using the maxSession property. Here is an example:

@MessageDriven(activationConfig = {
        @ActivationConfigProperty(propertyName = "maxSessions", propertyValue = "1"),
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
        @ActivationConfigProperty(propertyName = "destination", propertyValue = "TASK.QUEUE")
public class BuildTasksMessageListener implements MessageListener {

    public void onMessage(Message message) {
        try {


        } catch (JMSException e) {
            // Why can't I throw a JMS Exception
            throw new RuntimeException(e);

    // This is the only "useful" code in the class
    private void doSomethingUseful() {


You can also set the max-session attribute in the XML descriptor:


By setting max-session to 1 will essentially give you a singleton MDB.

Warning:  a Message Driven Bean configured to run as Singleton can soon become a bottleneck for your application. If you want a higher scalability / availability of your MDB you should consider increasing the number of MDB session instead.

Older JBoss versions

If you are running JBoss 4/5/6 you can configure this at EJB container level by changing the server/$/deploy/ejb3-interceptors-aop.xml file:

<annotation expr="!class(@org.jboss.annotation.ejb.DefaultActivationSpecs)">
  @org.jboss.annotation.ejb.DefaultActivationSpecs (value={@~ActivationConfigProperty(propertyName = "maxSession", propertyValue = "1")})

This will set the default for all message driven beans.