2. Using the Tutorial Examples 3. Getting Started with Web Applications 5. JavaServer Pages Technology 7. JavaServer Pages Standard Tag Library 10. JavaServer Faces Technology 11. Using JavaServer Faces Technology in JSP Pages 12. Developing with JavaServer Faces Technology 13. Creating Custom UI Components 14. Configuring JavaServer Faces Applications 15. Internationalizing and Localizing Web Applications 16. Building Web Services with JAX-WS 17. Binding between XML Schema and Java Classes 19. SOAP with Attachments API for Java What Is a Message-Driven Bean? What Makes Message-Driven Beans Different from Session Beans? When to Use Message-Driven Beans Defining Client Access with Interfaces Deciding on Remote or Local Access The Contents of an Enterprise Bean Naming Conventions for Enterprise Beans The Life Cycles of Enterprise Beans The Life Cycle of a Stateful Session Bean Further Information about Enterprise Beans 21. Getting Started with Enterprise Beans 23. A Message-Driven Bean Example 24. Introduction to the Java Persistence API 25. Persistence in the Web Tier 26. Persistence in the EJB Tier 27. The Java Persistence Query Language 28. Introduction to Security in the Java EE Platform 29. Securing Java EE Applications 31. The Java Message Service API 32. Java EE Examples Using the JMS API 36. The Coffee Break Application | The Life Cycles of Enterprise BeansAn enterprise bean goes through various stages during its lifetime, or life cycle.Each type of enterprise bean (stateful session, stateless session, or message-driven) has adifferent life cycle. The descriptions that follow refer to methods that are explained along with thecode examples in the next two chapters. If you are new toenterprise beans, you should skip this section and run the code examples first. The Life Cycle of a Stateful Session BeanFigure 20-3 illustrates the stages that a session bean passes through during its lifetime.The client initiates the life cycle by obtaining a reference to a statefulsession bean. The container performs any dependency injection and then invokes the method annotatedwith@PostConstruct, if any. The bean is now ready to have its businessmethods invoked by the client. Figure 20-3 Life Cycle of a Stateful Session Bean ![]() While in the ready stage, the EJB container may decide to deactivate, orpassivate, the bean by moving it from memory to secondary storage. (Typically, theEJB container uses a least-recently-used algorithm to select a bean for passivation.) TheEJB container invokes the method annotated@PrePassivate, if any, immediately before passivating it. Ifa client invokes a business method on the bean while it is inthe passive stage, the EJB container activates the bean, calls the method annotated@PostActivate, if any, and then moves it to the ready stage. At the end of the life cycle, the client invokes a methodannotated@Remove, and the EJB container calls the method annotated@PreDestroy, ifany. The bean’s instance is then ready for garbage collection. Your code controls the invocation of only one life-cycle method: the method annotated@Remove. All other methods inFigure 20-3 are invoked by the EJB container. SeeChapter 34, Resource Connections for more information. The Life Cycle of a Stateless Session BeanBecause a stateless session bean is never passivated, its life cycle has onlytwo stages: nonexistent and ready for the invocation of business methods.Figure 20-4 illustrates thestages of a stateless session bean. Figure 20-4 Life Cycle of a Stateless Session Bean ![]() The client initiates the life cycle by obtaining a reference to astateless session bean. The container performs any dependency injection and then invokes the methodannotated@PostConstruct, if any. The bean is now ready to have its businessmethods invoked by the client. At the end of the life cycle, the EJB container calls themethod annotated@PreDestroy, if any. The bean’s instance is then ready for garbagecollection. The Life Cycle of a Message-Driven BeanFigure 20-5 illustrates the stages in the life cycle of a message-driven bean. Figure 20-5 Life Cycle of a Message-Driven Bean ![]() The EJB container usually creates a pool of message-driven bean instances. For eachinstance, the EJB container performs these tasks:
Like a stateless session bean, a message-driven bean is never passivated, and ithas only two states: nonexistent and ready to receive messages. At the end of the life cycle, the container calls the methodannotated@PreDestroy, if any. The bean’s instance is then ready for garbage collection. Copyright © 2010, Oracle and/or its affiliates. All rights reserved.Legal Notices |