Architectural overview: Session beans

Clients share the Home, but never the bean.

Each client gets his own EJBObject reference and his own bean. The client never shares a bean with another client, although the meaning of “shares” depends on whether the bean is stateful or stateless. (We’ll see that in the next chapter.) However, there’s only one Home object for this particular bean type (say, AdviceBean), so both clients have a stub to the one and only Advice Home. Both clients ask the same Advice Home for a reference to an Advice bean. (Of course, the client never gets the reference to the bean instance, but instead gets a reference to the bean’s EJBObject. And since EJBObject is Remote, the clients gets a stub.)

image with no caption

A session bean client is guaranteed to be the only client executing a method on that bean. While the client is in the middle of a business method, that bean belongs to that client.

Get Head First EJB now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.