To EJB, or not to EJB?
Addressing the issues and decisions that go into adopting an EJB-based solution
By Humphrey Sheil, JavaWorld.com, 12/07/01
- Digg
- Reddit
- SlashDot
- Stumble
- del.icio.us
- Technorati
- dzone
To EJB, or not to EJB: that is the question.
Whether 'tis nobler in the mind, to suffer
The slings and arrows of outrageous licensing;
Or to take arms against a sea of potential overheads and features,
And by opposing end them? To roll your own: to reinvent the wheel;
No more; and by reinvent, to say, we continue
The heart-ache of low-level systems maintained in-house,
and the thousand natural shocks
That flesh is heir to; 'tis a consummation
Devoutly to be avoided.
(For Shakespeare's original "To be, or not to be," speech from Hamlet, see the sidebar.)
Once you have forgiven me for taking Hamlet apart with a chainsaw, you will realize that the lines above sum up the quandary
every J2EE (Java 2 Platform, Enterprise Edition) architect faces: Are you over engineering your solution by employing EJB
(Enterprise JavaBean) technology when the signs point to a different approach, indeed, perhaps a different technology? On
the other hand, if you decide not to specify an EJB-based solution, have you subsequently found that a sizeable chunk of your
code (that must be maintained) handles tasks best addressed by a container or a server?
This article shares with you how I methodically answer these questions.
Before I begin, let me set your expectations and explain my motivations for writing this article. First up, I do not answer
the EJB/not EJB question for you, but I do provide a toolkit with which you can answer that question for yourself. Second,
I have no hidden agendas: I do not represent an EJB server vendor, so I won't push EJBs for everything. On the other hand,
I do not represent a technology or technique competing with EJB, apart from presenting it to you here as an alternative, so
I won't deride an EJB solution where it makes sense.
Indeed, my motivation for this article stems from reader requests following my last JavaWorld article, "J2EE Project Dangers." In that article, I briefly touched on the danger of over-engineering, specifically around EJBs. Many readers requested
a more in-depth treatise on the subject -- so here it is!
With that in mind, I propose to proceed as follows: In order to understand if you need EJB, you must understand an EJB solution's
main advantages and disadvantages. As with all technologies, EJB has its weak points, and knowing these weak points is the
first step to avoiding them. Following the discussion on EJB's weaknesses, I briefly outline alternatives to an EJB-based
solution, both inside and outside the Java/J2EE world.
The final section is a proofing check. When you reach this part of the article, you should be comfortable applying the principles
previously outlined to any business scenario. In that section, I present a progressive scenario that requires a solution (I
promise not to pick either a pet store or an ATM machine!), make my call on the EJB/no EJB decision, and let you agree or
disagree with my reasoning.
EJB advantages and disadvantages
Moving along, let's look at EJB's strong and weak points. In the disadvantages section, I also give solutions to commonly
encountered EJB weaknesses.
- Digg
- Reddit
- SlashDot
- Stumble
- del.icio.us
- Technorati
- dzone
Resources
- See for yourself how I mutilated Shakespeare's original "To be, or not to be," speech from Hamlet in the sidebar.
- Reader inquiries about my second JavaWorld article, "J2EE Project Dangers," (March 2001) prompted me to write the above article
http://www.javaworld.com/javaworld/jw-03-2001/jw-0330-ten.html
- You can download the Enterprise JavaBeans 2.0 Specification from
http://java.sun.com/products/ejb/docs.html
- The Jakarta Project's free Ant build tool removes much of the pain in deploying EJBs to application servers, and, best of
all, it's extensible
http://jakarta.apache.org/ant
- Check out XDoclet for an elegant way to reduce hand-maintained code and increase efficiency through auto-generation
http://xdoclet.sourceforge.net
- "Designing Enterprise Applications with the J2EE Platform" (Sun Microsystems, 2001) from the J2EE Blueprints series offers good information on design patterns for EJB/J2EE projects
http://java.sun.com/blueprints/guidelines/designing_enterprise_applications/index.html
- The OMG produces and maintains computer industry specifications for interoperable enterprise applications, most notably CORBA
http://www.omg.org
- Jini.org offers in-depth information about Jini and JavaSpaces
http://www.jini.org
- Sandstorm, an interesting technology out of the University of California, Berkeley, provides good information for scalable
applications
http://www.cs.berkeley.edu/~mdw/papers/seda-sosp01.pdf
- For more information on .Net, check out this site, specifically designed to appeal to developers and architects
http://gotdotnet.com/
- "GartnerDon't Overspend on Application Server Tech," Scarlet Pruit (NetworkWorldFusion, August 2001) -- like all research notes, this one is refreshingly honest and wonderfully accurate
http://www.nwfusion.com/news/2001/0821gartnerapp.html
- My first JavaWorld article, "Frameworks Save the Day" (September 2000), outlines the basic necessities of a J2EE framework and also an extension
strategy. If you're not using a standard framework on your project, you are leaving yourself open to a whole raft of quality
and maintenance issues
http://www.javaworld.com/javaworld/jw-09-2000/jw-0929-ejbframe.html
- Born and bred from XP (extreme programming) and JUnit, continuous integration makes your development cycle a lot easier
http://www.martinfowler.com/articles/continuousIntegration.html
- For more EJB stories, visit the Enterprise JavaBeans section of JavaWorld's Topical Index
http://www.javaworld.com/channel_content/jw-ejbs-index.shtml
- Discuss EJB in our Enterprise Java discussion
http://forums.idg.net/webx?50@@.ee6b80a
- Sign up for JavaWorld's free Enterprise Java newsletter
http://www.javaworld.com/subscribe
- You'll find a wealth of IT-related articles from our sister publications at IDG.net
I wish I've had read this article before attending the job interBy Anonymous on January 27, 2010, 8:47 amI wish I've had read this article before attending the job interview today. I was using EJBs in my past projects but didn't know about the alternatives or why I...
Reply | Read entire comment
Great articalBy Anonymous on May 18, 2009, 10:02 pmI was was unsure about the issues for and against EJB and this articles was great in helping me fully understand them!
Reply | Read entire comment
View all comments