12.07.2015 Views

Beginning Java EE 6 with GlassFish 3, Second Edition

Beginning Java EE 6 with GlassFish 3, Second Edition

Beginning Java EE 6 with GlassFish 3, Second Edition

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 8 ■ CALLBACKS AND INTERCEPTORS5. If the client remains idle for a period of time, the container invokes the methodannotated <strong>with</strong> @PrePassivate, if any, and passivates the bean instance into apermanent storage.6. If the client invokes a passivated bean, the container activates it back tomemory and invokes the method annotated <strong>with</strong> @PostActivate, if any.7. If the client does not invoke a passivated bean instance for the session timeoutperiod, it is destroyed by the container.8. Alternatively to step 7, if the client calls a method annotated by @Remove, thecontainer then invokes the method annotated <strong>with</strong> @PreDestroy, if any, andends the life of the bean instance.Figure 8-2. Stateful bean life cycleIn some cases, a stateful bean contains open resources such as network sockets or databaseconnections. Because a container cannot keep these resources open for each bean, you will have to closeand reopen the resources before and after passivation. That’s when life-cycle callback methods can beused.CallbacksAs you just saw, each session bean has its own container-managed life cycle. The container lets youoptionally provide your own business code when the state of the bean changes. The change from onestate to another can be intercepted by the container to invoke methods annotated by one of theannotations listed in Table 8-1.240

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!