The Lifecycle of a Message-Driven Bean
Just as session beans have well-defined lifecycles, so does the message-driven bean. The MDB instance’s lifecycle has two states: Does Not Exist and Method-Ready Pool. The Method-Ready Pool is similar to the instance pool used for stateless session beans.[16] Figure 8-5 illustrates the states and transitions that an MDB instance goes through in its lifetime.
Figure 8-5. MDB lifecycle
The Does Not Exist State
When an MDB instance is in the Does Not Exist state, it is not an instance in the memory of the system. In other words, it has not been instantiated yet.
The Method-Ready Pool
MDB instances enter the Method-Ready Pool as the container needs them. When the EJB server is first started, it may create a number of MDB instances and enter them into the Method-Ready Pool (the actual behavior of the server depends on the implementation). When the number of MDB instances handling incoming messages is insufficient, more can be created and added to the pool.
Transitioning to the Method-Ready Pool
When an instance transitions from the Does Not Exist state to
the Method-Ready Pool, three operations are performed on it. First,
the bean instance is instantiated by invoking the Class.newInstance()
method on the bean implementation class. Second, the container injects any resources that the bean’s metadata has requested via an injection annotation or XML deployment ...
Get Enterprise JavaBeans 3.1, 6th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.