What's an EJB?

Let's first understand the meaning of component and server component model, and then examine the meaning of EJB. A component is a piece of code that implements well-defined interfaces. Typically, it lives in a runtime environment and takes advantage of the services offered by the environment. For the component to live in a runtime environment, it must follow the rules of the runtime environment. This ensures the proper functioning of the runtime environment and the portability and scalability of the component. A component is not a complete application. An application consists of multiple components working together.

Generally, developing server-side objects is more difficult than writing graphical user interface (GUI) or client components. This is because in addition to writing business application logic, the developers must also take care of system-level issues such as multithreading, access to databases, efficient management of resources, transactions, security, access to legacy systems, and so on. A server component model or architecture provides support for server-side components. This simplifies the development of server-side components and allows developers to focus on developing business application logic.

An enterprise bean is a server-side component that implements the business logic of an enterprise application and adheres to the rules of the Enterprise JavaBean architecture. Enterprise beans live in an EJB container—a runtime environment within a J2EE server. The EJB container provides multiple services to support the enterprise beans.

Note

The Enterprise JavaBeans specification states, “The Enterprise JavaBeans architecture is a component architecture for the development and deployment of component-based distributed business applications. Applications written using the Enterprise JavaBeans architecture are scalable, transactional, and multi-user secure. These applications may be written once, and then deployed on any server platform that supports the Enterprise JavaBeans specification. The Enterprise JavaBeans architecture will make it easy to write applications: Application developers will not have to understand low-level transaction and state management details, multi-threading, connection pooling, and other complex low-level APIs.” The entire 500+ pages of the specification, meant for application server vendors to digest and implement, can be accessed at http://java.sun.com/products/ejb/docs.html.


Note

EJB is an overloaded name. Depending on the context, it represents either a server-side component, or component-based architecture. We'll use the terms EJB, Enterprise Bean, and Enterprise JavaBean interchangeably in this book. Unless otherwise mentioned, we'll use the term bean to mean EJB.


The following are the characteristics of EJBs:

  • They contain business logic that operates on the enterprise's data.

  • They depend on a container environment to supply life-cycle services for them. EJB instances are created and maintained by the container.

  • They can be customized at deployment time by editing the deployment descriptor.

  • System-level services, such as transaction management and security, are described separately from the enterprise bean.

  • A client never accesses an enterprise bean directly; the container environment mediates access for the client. This provides component-location transparency.

  • The EJB is designed to be portable across EJB servers provided by different vendors.

  • They can be included in an assembled application without requiring source code changes or recompilation of them.

  • Beans are always single threaded; you never have to write thread-safe code. You design your threads as single-threaded components, and the EJB container handles multiple client requests by load balancing and instantiating multiple instances of the single-threaded components.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.242.235