Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

What is EJB

EJB is an acronym for enterprise java bean. It is a specification provided by Sun Microsystems to
develop secured, robust and scalable distributed applications.

The EJB enumeration was originally developed by IBM in 1997 and later adopted by Sun
Microsystems in 1999 and enhanced under the Java Community Process.

To run EJB application, you need an application server (EJB Container) such as Jboss, Glassfish,
Weblogic, Websphere etc. It performs:

a. life cycle management, security, transaction management,


and
b. object pooling.

EJB application is deployed on the server, so it is called server side component also.

When use Enterprise Java Bean?


1. Application needs Remote Access. In other words, it is distributed.
2. Application needs to be scalable. EJB applications supports load balancing, clustering
and fail-over.
3. Application needs encapsulated business logic. EJB application is separated from
presentation and persistent layer.

Types of Enterprise Java Bean

There are 3 types of enterprise bean in java.

Session Bean

Session bean contains business logic that can be invoked by local, remote or webservice client.

 (i) Stateful Session bean :


Stateful session bean performs business task with the help of a state.
Stateful session bean can be used to access various method calls by storing
the information in an instance variable. Some of the applications require
information to be stored across separate method calls. In a shopping site,
the items chosen by a customer must be stored as data is an example of
stateful session bean.
 (ii) Stateless Session bean :
Stateless session bean implement business logic without having a persistent
storage mechanism, such as a state or database and can used shared data.
Stateless session bean can be used in situations where information is not
required to used across call methods.

Message Driven Bean

Like Session Bean, it contains the business logic but it is invoked by passing message.

Entity Bean

It encapsulates the state that can be persisted in the database. It is deprecated. Now, it is
replaced with JPA (Java Persistent API).

Difference between RMI and EJB

Both RMI and EJB, provides services to access an object running in another JVM (known as
remote object) from another JVM. The differences between RMI and EJB are given below:

RMI EJB

In RMI, middleware services such as security, In EJB, middleware services are


transaction management, object pooling etc. need provided by EJB Container
to be done by the java programmer. automatically.

RMI is not a server-side component. It is not EJB is a server-side component,


required to be deployed on the server. it is required to be deployed on
the server.

RMI is built on the top of socket programming. EJB technology is built on the
top of RMI.
Advantages of Enterprise Java Beans
1. EJB repository yields system-level services to enterprise beans, the bean developer can
focus on solving business problems. Rather than the bean developer, the EJB repository is
responsible for system-level services such as transaction management and security
authorization.

2. The beans rather than the clients contain the application’s business logic, the client
developer can focus on the presentation of the client. The client developer does not have to
code the pattern that execute business rules or access databases. Due to this the clients are
thinner which is a benefit that is particularly important for clients that run on small devices.
3. Enterprise Java Beans are portable elements, the application assembler can build new
applications from the beans that already exists.

Disadvantages of EJB
1. Requires application server
2. Requires only java client. For other language client, you need to go for webservice.
3. Complex to understand and develop ejb applications.
4.
5. Difference between web server and application server:
S.NOWeb Server Application Server

While application server encompasses Web


1. Web server encompasses web container only. container as well as EJB container.
Whereas application server is fitted for dynamic
2. Web server is useful or fitted for static content. content.
3. Web server consumes or utilizes less resources.While application server utilize more resources.
Web servers arrange the run environment for While application servers arrange the run
4. web applications. environment for enterprises applications.
While in application server, multithreading is not
5. In web servers, multithreading is supported. supported.
Web server’s capacity is lower than application While application server’s capacity is higher than
6. server. web server.
In web server, HTML and HTTP protocols are While in this, GUI as well as HTTP and RPC/RMI
7. used. protocols are used.
Processes that are not resource-intensive are
8. supported. Processes that are resource-intensive are supported.
Transactions and connection pooling is not
9. supported. Transactions and connection pooling is supported.
The capacity of fault tolerance is low as
10. compared to application servers. It has high fault tolerance.
Web Server examples are Apache HTTP
11. Server , Nginx. Application Servers example are JBoss , Glassfish.
EJB Container

EJB is a server-side software element that summarizes the business logic of an


application. Enterprise Java Beans

web repository yields a runtime domain for web-related software elements including computer
reliability, Java Servlet Lifecycle (JSL) management, transaction procedure, and other web services.

What does an EJB container do?

EJB container performs the following tasks:

o Instantiate beans on demand


o Manages a pool of bean instances
o Manage Transactions
o Loads/ saves bean data from/to a database
o Handles Security
o Provides other System Services

EJB Container Services

EJB Container provides the following valuable services for enterprise application development.

o Transaction support (start, rollback, and commit)


o Security Model
o Persistence Support
o Timing Services and Job Scheduling
o Messaging
o Remote Access
o Distribution
o Web-services
o Component Pooling
o Component Life-cycle Interceptors Asynchronous Interactions
o Thread-safety and Concurrency Control

You might also like