EJB3 Introduction

26 December 2011 By Nithya Vasudevan 8,539 views No Comment
16 Flares Twitter 1 Facebook 11 Google+ 4 16 Flares ×


Enterprise JavaBeans (EJB) is server-side component model of the Java platform for developing distributed enterprise applications.

It enables enterprises develop “secure, scalable, multi-platform, business-critical applications as server-side components”

The EJB specification is part of Java EE specification which encapsulates the business logic of an application.

Applications developed using EJB run on Java EE Application Servers which include an EJB container by default or a standalone EJB container can be used. (More on this later).

The main point of EJB was to allow enterprise developers to concentrate on business logic and free them from the need to write transaction, security, caching, pooling and threading primitives by delegating that task to the server vendor.

When to use EJB?

If your application,

  1. Needs to encapsulate business logic
    • Business logic is separated from presentation and persistence tier
  2. Needs Remote access
    • Applications running on different servers can access EJB.
  3. Needs to be scalable
    • Almost all Java EE application servers support clustering, load balancing, and failover
  4. Needs Broad vendor support
    • JBoss, Oracle AS, WebLogic, WebSphere, Glassfish, etc are some of Java EE Application Servers.
  5. Needs to be portable
    • Applications developed using EJB can be written once and deployed on different Java EE Application Servers
  6. Needs deployment time configuration
    • Enables deployment-time configuration using XML-based deployment descriptor or within the bean’s code using metadata deployment annotations.

Disadvantages of EJB:

  1. Complexity
    • EJB specification is too large and complicated. Even though EJB might be simpler than other remote object systems, remote-object frameworks are much more complex than local-object frameworks.
    • Spring is easier and more powerful for local access
  2. Requires Java EE server
    • Can’t run on Web Containers such as Tomcat, Jetty, Resin, JRun, Resin
    • Java EE servers are usually hard to configure, significantly slower to start/restart during development and testing, and usually cost money
  3. Bad name due to earlier releases
    • EJB2 was so complex that EJB has bad reputation till this day
  4. Needs Java Clients
    • EJBs are built on top of RMI. Both involve Java clients and beans. If your clients need to be written in something else (e.g., .NET, PHP, etc.) then you have to go with web services or something else that is a platform independent protocol, like HTTP, XML over HTTP or SOAP.


  • If you don’t want to use EJB , you have two other choices:
    1. Lightweight open source Java framework – Spring.
    2. Microsoft .NET–managed components, part of the Microsoft .NET platform.

Tags: , ,