Creating a Message-Driven Bean

The setMessageDrivenContext() method can throw EJBException if there is a container or system level error of some kind. See the section called “Handling Exceptions” for more details. What follows is an example setMessageDrivenContext() method that saves its EJBContext and JNDI context:

private MessageDrivenContext mdbContext;
private Context jndiContext;
public void setMessageDrivenContext (MessageDrivenContext ctx) {
    mdbContext = ctx;
    try { jndiContext = new InitialContext();
    } catch (NamingException nameEx) {
        throw new EJBException(nameEx);
    }
}

After calling setMessageDrivenContext(), the container calls the bean's ejbCreate() method, which takes no parameters. You could use this method to allocate resources, ...

Get Sams Teach Yourself J2EE™ in 21 Days now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.