Bitter EJB
Bruce Tate, Mike Clark, Bob Lee, Patrick Linskey
  • May 2003
  • ISBN 9781930110953
  • 440 pages

...wonderful writing of the most enjoyable technical reads...explanation of the concepts is easy to absorb, entertaining, informative, and to the point.

Dave Wiltz, SBC Global

In Bitter EJB, Bruce Tate and his co-authors continue the entertaining and engaging writing style of relating true-life adventure sport experiences to antipattern themes established in Bruce's first book, the best selling Bitter Java.

This more advanced book explores antipatterns, or common traps, within the context of EJB technology.

Table of Contents show full



about this book

Part 1 The basics

1. Bitter choices

1.1. A storm of controversy

1.2. A history of EJB antipatterns

1.2.1. March 1998: EJB 1.0

1.2.2. March 1998: EJB 1.0

1.2.3. August 2001: EJB 2.0

1.3. A case study: Benchmarking PetStore

1.4. Antipattern: The Golden Hammer

1.4.1. Choosing unwisely

1.4.2. Solution: Evaluate carefully

1.5. Summary: Looking ahead

1.6. Antipatterns in this chapter

2. The bitter cost

2.1. Sparking controversy

2.1.1. The value of EJB

2.1.2. EJB-appropriate applications

2.1.3. Using a litmus test

2.1.4. Passing the test

2.1.5. Weighing complexity

2.1.6. Evaluating your talent

2.2. Antipattern: A Sledgehammer for a Fly

2.2.1. Adding complexity

2.2.2. Solution: Simplify

2.2.3. Consider the cost of managing many files

2.2.4. Grading the finer points

2.3. Entity beans are a horse of a different color

2.3.1. The black sheep of the bean family

2.4. Entity beans: Take two

2.4.1. Local interfaces

2.4.2. Container-managed relationships

2.5. Entity beans—a closer look

2.5.1. Employee management

2.6. Summary

2.7. Antipatterns in this chapter

3. Bitter interfaces

3.1. Building a good interface

3.1.1. Breaking down remote invocation performance

3.1.2. Passing by reference vs. value

3.2. Designing the application tier

3.2.1. Looking back on entity beans

3.2.2. Questioning EJB local interfaces

3.3. Antipattern: Local & Remote Interfaces Simultaneously

3.3.1. Combined interfaces muddle exception management

3.3.2. Combined interfaces hurt performance

3.3.3. Mini-antipattern: Ubiquitous Distribution

3.3.4. Mini-antipattern: Transparent Distribution

3.3.5. Solution: Achieving equilibrium

3.3.6. Knowing when to distribute

3.4. Antipattern: Customers in the Kitchen

3.4.1. Nudging the diners toward the door

3.4.2. Solution: Funnel the customers through a waiter

3.4.3. Using Data Transfer Objects

3.5. Antipattern: Custom DTOs

3.5.1. Solution: Refactor to preserve flexibility

3.6. Summary

3.7. Antipatterns in this chapter

Sessions and messages

4. Bitter sessions

4.1. Threading and synchronization

4.1.1. Antipattern: Tangled Threads

4.1.2. Solution: Standardization to the rescue

4.1.3. Coping with hung threads

4.1.4. Searching for a solution

4.2. Handling exceptions

4.2.1. Mini-antipattern: Logic in Exception Implementations

4.2.2. Solution: Refactor logic out of exceptions

4.2.3. Antipattern: Swallowing Exceptions

4.2.4. Solution: A simple exception handling strategy

4.2.5. Antipattern: Killer System Exceptions

4.2.6. Solution: Throw the correct exception type

4.3. Iterating large datasets

4.3.1. Antipattern: Database Connection Hog

4.3.2. Solution: Manage connections with surgical precision

4.3.3. Antipattern: Eager Iterator

4.3.4. Solution: Test, test, test

4.3.5. Caching results

4.3.6. Exporting results

4.3.7. Determining the size of a result set

4.3.8. Iterating shuffled data

4.4. Interoperating efficiently

4.4.1. Using IIOP

4.4.2. Antipattern: Narrow Servlet Bridges

4.4.3. Solution: A generic servlet bridge

4.5. Summary

4.6. Antipatterns in this chapter

5. Bitter session states

5.1. Making a case for session state

5.2. A pivotal antipattern: Conversational Baggage

5.2.1. The burden of state

5.2.2. Lightening the load

5.2.3. Solution 1: Strive for statelessness

5.2.4. Solution 2: Leverage session state when beneficial

5.3. Managing sessions with stateful session beans

5.3.1. Shopping using a stateful session bean

5.3.2. Looking under the hood

5.4. Managing sessions with servlets

5.4.1. Keeping it simple with HttpSession

5.4.2. Shopping using a servlet

5.4.3. Scaling up servlet sessions

5.5. Antipattern: Golden Hammers of Session State

5.5.1. Storing sessions on the client

5.5.2. Storing sessions on the server using servlets

5.5.3. Storing sessions on the server using stateful EJB

5.5.4. Storing sessions in a database

5.5.5. Revisiting the shopping cart

5.5.6. Overall solution: Pick the right tool for the job

5.6. Mini-antipattern: Stateful Session Beans as Shared Data Caches

5.7. Antipattern: Session Hodgepodge

5.7.1. Solution: Be explicit and conservative

5.8. Mini-antipattern: Session Thrashing

5.9. Mini-antipattern: Rotting Session Garbage

5.10. Summary: Taming the beast

5.11. Antipatterns in this chapter

6. Bitter messages

6.1. A brief overview of JMS

6.2. An early antipattern: Fat Messages

6.2.1. One size doesn’t fit all

6.2.2. Solution 1: Put messages on a diet

6.2.3. Solution 2: Use references

6.3. Mini-antipattern: Skinny Messages

6.3.1. Solution: Use state to allow lazy loading

6.4. Seeds of an order processing system

6.4.1. Defining the system

6.4.2. Designing messages

6.4.3. Choosing messaging models

6.4.4. Responding to change

6.4.5. Building the OrderRequest producer

6.5. Antipattern: XML as the Silver Bullet

6.5.1. Solution: Use XML messages judiciously

6.6. Antipattern: Packrat

6.6.1. Putting a price on persistence

6.6.2. Paying for durable subscriptions

6.6.3. Solution: Save only what’s important

6.7. Mini-antipattern: Immediate Reply Requested

6.8. Using message-driven beans (MDBs)

6.8.1. Pooling with MDBs

6.8.2. Building the OrderRequest consumer

6.9. Antipattern: Monolithic Consumer

6.9.1. Listening to the test

6.9.2. Solution: Delegate to modular components

6.10. Antipattern: Hot Potato

6.10.1. Solution: Acknowledge the message, not its result

6.11. Antipattern: Slow Eater

6.11.1. Solution: Eat faster, if you can

6.12. Antipattern: Eavesdropping

6.12.1. Solution: Use message selectors

6.12.2. Declaring message selectors

6.12.3. Going beyond message selectors

6.13. Antipattern: Performance Afterthoughts

6.13.1. Solution: Measure early and often

6.14. Summary: Getting the message

6.15. Antipatterns in this chapter

EJB persistence

7. Bitter entities

7.1. Understanding entity bean antipatterns

7.1.1. Understanding the entity bean antipattern landscape

7.2. Antipattern: Face Off

7.2.1. Network round-tripping chokes applications

7.2.2. Losing transactional integrity

7.2.3. Solution: A Session Façade

7.2.4. Using a façade for transactional integrity

7.2.5. Using local interfaces

7.3. Antipattern: Ham Sandwich; Hold the Ham

7.3.1. The choice between BMP and CMP

7.3.2. Solution: Choose CMP when possible

7.4. Antipattern: Application Joins

7.4.1. Solution: Delegate joins to the database

7.4.2. Common examples of application joins

7.5. Antipattern: Application Filters

7.5.1. Understanding the types of application filters

7.6. Antipattern: Rusty Keys

7.6.1. Solution: shorten your primary key

7.7. Antipattern: Revolving Doors

7.7.1. Solution 1: Refactor to avoid re-entrancy

7.7.2. Solution 2: Disable the container’s re-entrancy checking

7.7.3. Solution 3: Lobby the EJB specification team

7.8. Summary

7.9. Antipatterns in this chapter

8. Bitter alternatives

8.1. Understanding entity bean alternatives

8.2. Using EJB persistence

8.2.1. Implementing CMP

8.2.2. Adding the DTO and facade

8.2.3. Including deployment details

8.2.4. Rolling your own with BMP entity beans

8.3. Simplify with JDBC

8.3.1. Implementing a simple JDBC model

8.3.2. Implementing the JDBC Façade

8.3.3. Deploying a Session Façade for JDBC

8.4. Using object persistence frameworks

8.4.1. Surveying the object persistence landscape

8.4.2. Understanding JDO

8.4.3. Implementing a simple model with JDO

8.4.4. Implementing the JDO model’s façade

8.4.5. Deploying the solution

8.4.6. Comparing the options

8.5. Antipattern: Persistent Problems

8.5.1. Generic entity bean weaknesses

8.5.2. Inheritance and polymorphism

8.5.3. Query language flexibility is often critical

8.5.4. DTOs require non-EJB solutions for local entities

8.5.5. Container-bound persistence

8.6. Solution: Do not "inherit" a persistence architecture—choose it

8.7. Summary

8.8. Antipatterns in this chapter

Broader topics

9. Bitter tunes

9.1. Measures of success

9.1.1. Response time

9.1.2. Throughput

9.2. Antipattern: Premature Optimization

9.2.1. Tuning EJB applications blindfolded

9.2.2. Solution 1: Plan, but don’t act (yet)

9.2.3. Solution 2: Write well-factored, modular code

9.3. Antipattern: Performance Afterthoughts

9.3.1. Solution: Plan early and often

9.4. Grist for the tuning mill

9.4.1. Putting an EJB to the test

9.4.2. Passing the test

9.4.3. Specifying response time as a measure of success

9.4.4. Seeing light at the end of the tuning tunnel

9.5. Antipattern: Thrash-tuning

9.5.1. Solution: Use a performance testing methodology

9.6. Mini-antipattern: Manual Performance Testing

9.6.1. Solution: Automate performance testing

9.7. Automated performance testing with JUnitPerf

9.7.1. JUnitPerf overview

9.7.2. Testing response time

9.7.3. Tweaking code

9.7.4. Specifying scalability as a measure of success

9.7.5. Testing response time under load

9.7.6. Using a connection pool to increase throughput

9.7.7. Testing throughput

9.8. Modeling performance

9.9. Mini-antipattern: Stage Fright

9.9.1. Solution: Practice on stage

9.10. Summary: Tuning with confidence

9.11. Antipatterns in this chapter

10. Bitter builds

10.1. Wrapping big packages without bows

10.1.1. Understanding an example EJB

10.1.2. Organizing your directory structure

10.1.3. Filling the EJB JAR

10.1.4. Loading classes

10.2. Antipattern: System Loaded Application Classes

10.2.1. Solution: Follow the J2EE guidelines

10.3. Antipattern: EJB Code Duplication

10.3.1. Solution: Autogenerate the EJB classes

10.3.2. Solution: Autogenerate the manifest

10.3.3. Solution: Autogenerate the EAR descriptor

10.4. Antipattern: Build Guru

10.4.1. Solution: Use Ant for heavy lifting

10.5. Antipattern: Running with Scissors

10.5.1. Solution: Test with impunity

10.6. Antipattern: Integration Hell

10.6.1. Solution: Integrate early, often, and automatically

10.7. Summary

10.8. Antipatterns in this chapter

11. A bittersweet future

11.1. Marking our place in history

11.1.1. Early mistakes

11.2. Plotting the next moves

11.2.1. Into the future

11.2.2. Fix persistence

11.2.3. Fix the deployment strategy

11.2.4. Putting the economic house in order

11.3. Antipatterns and next moves

Appendix A: Bitter tales

A.1. A Java development free fall

A.1.1. Antipatterns in life

A.2. Using design patterns accentuates the positive

A.2.1. Design patterns online

A.2.2. UML provides a language for patterns

A.3. Antipatterns teach from the negative

A.3.1. Some well-known antipatterns

A.3.2. Antipatterns in practice

A.3.3. Antipattern resources

A.4. Antipattern ideas are not new

A.4.1. Learning from the industry

A.4.2. Detective work

A.4.3. Refactoring antipatterns

A.5. Why Bitter Java?

A.5.1. The Bitter Java approach

A.5.2. Bitter Java tools

A.5.3. The Bitter Java organization

A.5.4. The Bitter Java audience

A.6. Looking ahead

Appendix B: Bitter basics

B.1. Developing in the EJB architecture

B.1.1. Getting acquainted with the cast, the bean triad

B.1.2. Know your host, the EJB container

B.2. Crafting enterprise beans

B.2.1. Defining the client interfaces

B.2.2. Implementing the business logic

B.2.3. Playing it safe with transactions

B.2.4. Configuring the bean

B.2.5. Packaging it

B.2.6. Invoking your beans from a client



About the book

EJB is experiencing the mixture of practical success and controversy that accompanies a new and quickly-changing framework. Bitter EJB takes the swirling EJB controversies head-on. It offers a practical approach to design: how to become a better programmer by studying problems and solutions to the most important problems surrounding the technology.

The flip side of design patterns, antipatterns, are a fun and interesting way to take EJB expertise to the next level. The book covers many different aspects of EJB, from transactions to persistence to messaging, as well as performanceand testing.

What's inside

Bitter EJB will teach programmers to do the following:

  • Identify EJB persistence strategies
  • Choose Entity bean alternatives
  • Use EJB message driven beans
  • Know when to apply or avoid stateful session beans
  • Create efficient build strategies with XDoclet, Ant and JUnit
  • Automate performance tuning

About the authors

Bruce Tate's consulting career spans fifteen years, including a ten-year stint at IBM. He's now an independent consult in Austin, TX where he works with the Middleware Company and other clients to promote and teach effective Java design. He wrote the smash hit, Bitter Java as the first of Manning's Bitter books.

Mike Clark is president of Clarkware Consulting, Inc. in Denver, CO. He has been crafting software professionally since 1992, immersed in Java since 1997.

Bob Lee, an independent consultant and open source developer working out of St. Louis, MO, has over 10 years of software development experience. Bob hosts a Java-themed web log at; feel free to visit and join Bob in his ongoing bitter journey.

Patrick Linskey is the VP of Engineering for a Java persistence company called SolarMetric in Washington, DC. He's spent the last two years building a company to offer Java persistence alternatives to the Java community.

eBook $35.99 PDF only

FREE domestic shipping on three or more pBooks

...helps you cut through the hype surrounding enterprise Java development.

John D. Crabtree, Taliant Software

They know their stuff, and that is obvious

Jack Herrington, Code Generation Network awesome read.

Barry Nowak, GFS Marketplace

...helps you spot the dead-ends and points you in the right direction, before you start tearing your hair out.

Jon Skeet, Peramon Technology