EJB Container
EJB Container

In this course, we will learn the concepts of Java EE 7 with a focus on Enterprise Java Beans (EJB).

Learning Objectives

  • Enterprise Java Beans (EJB)

Intended Audience

  • Anyone looking to get Oracle Java Certification
  • Those who want to improve Java 7 EE knowledge
  • Java developers


  • Have at least 2 years of Java development experience 

Hello dear friends. In this video, we will examine the EJB container. Let's begin. Enterprise Beans  are Java programming language server components that contain business logic. EJB container is a server-side component that comprises the business logic. The EJB container provides local and remote access to Enterprise Beans. In other words, we can say that it provides a runtime environment for EJB applications within the application server. A single EJB container can have one or more EJB modules. It acts as an intermediate action between business logic and enterprise application. The following figure depicts the structure of the EJB container; The container is responsible for creating the Enterprise Bean, binding the Enterprise Bean to the naming service, so other application components can access the Enterprise Bean, ensuring only authorized clients have access to the Enterprise Bean's methods, saving the Beans state to persistent storage, caching the state of the Bean, and activating or passivating the Bean when necessary. Java EE expects a developer to create an Enterprise Java Bean, a simple component, and the EJB container to provide the infrastructure required for communications, transactions, and data access.

It converts business logic into executable code. In addition, the EJB container provides lifecycle management for the component to ensure that its creation, usage, and destruction are both efficient and in accord with specification. Let's examine the inheritance dependencies, methods and interfaces that define the EJB container. When the EJB container is started, it has at its highest level the EJB container IMP one-class as its controller. It is a subclass of the generic container IMP one-class. EJB container IMP one implements the EJB container service interface and has listeners for changes to the deployed application modules and other parts of the environment. However, if we look at the WS Component interface, we can see some key methods that explain how the components and therefore the container are controlled by the WAS Runtime environment. The container IMP one-class is a subclass of the component IMP one-class. So, it can be treated like any other component by the load components calls of the outer container that initializes it. It's how the base server starts, controls and interacts with the EJB container.

As I said, an EJB is a server side component and needs to be executed in a container. This runtime environment provides core features common to many enterprise applications, like remote client communication. Without writing any complex code, an EJB client can invoke methods remotely via standard protocols. Dependency injection; The container can inject several resources into an EJB like JMS destinations and factories, data sources, other EJBs, environment variables, etc. State management; for state-full Session Beans the container manages their state transparently. You can maintain state for a particular client as if you were developing a desktop application. Pooling; for stateless beans and MDBs, the container creates a pool of instances that can be shared by multiple clients. Once invoked, an EJB returns to the pool to be reused instead of being destroyed.

Component lifecycle; The container is responsible for managing the lifecycle of each component. Messaging; The container allows MDBs to listen to destinations and consume messages without too much JMS Pluming. Transaction management; With declarative transaction management an EJB can use annotations to inform the container about the transaction policy it should use. The container takes care of the commit or the rollback. Security; class or method level access control can be specified on EJBs to enforce user and role authentication. Concurrency support; except for singleton's, where some concurrency declaration is needed, all other types of EJB are thread safe by nature. You can develop high performance applications without worrying about thread issues. Interceptors; Cross-cutting concerns can be put into interceptors, which will be invoked automatically by the container. Asynchronous method invocation; With EJB 3.1, it's now possible to have asynchronous calls without involving messaging. Once the EJB is deployed, the container takes care of these features, leaving the developer to focus on business logic while benefiting from these services without adding any system level code. That's all I have to say about the EJB container. In the following video, we will continue with the EJB types and Session Beans. See you in the following video.


About the Author
Learning Paths

OAK Academy is made up of tech experts who have been in the sector for years and years and are deeply rooted in the tech world. They specialize in critical areas like cybersecurity, coding, IT, game development, app monetization, and mobile development.

Covered Topics