Skip to Main Content
Enterprise JavaBeans 3.1, 6th Edition
book

Enterprise JavaBeans 3.1, 6th Edition

by Andrew Lee Rubinger, Bill Burke
September 2010
Intermediate to advanced content levelIntermediate to advanced
766 pages
18h 35m
English
O'Reilly Media, Inc.
Content preview from Enterprise JavaBeans 3.1, 6th Edition

Lifecycle Callbacks

Some services require some initialization or cleanup to be used properly. For example, a file transfer module may want to open a connection to a remote server before processing requests to transfer files and should safely release all resources before being brought out of service.

For component types that have a lifecycle, EJB allows for callback notifications, which act as a hook for the bean provider to receive these events. In the case of our file transfer bean, this may look like:

prototype FileTransferService
{
  @StartLifecycleCallback
  function openConnection(){ ... }

  @StopLifecycleCallback
  function closeConnection() { ... }
}

Here we’ve annotated functions to open and close connections as callbacks; they’ll be invoked by the container as their corresponding lifecycle states are reached.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Reinventing the Organization for GenAI and LLMs

Reinventing the Organization for GenAI and LLMs

Ethan Mollick
JavaServer Faces

JavaServer Faces

Hans Bergsten
EJB 3 Developer Guide

EJB 3 Developer Guide

Michael Sikora

Publisher Resources

ISBN: 9781449399139Errata Page