Best Practices

Stateless beans offer better performance than stateful beans. Activation and passivation are expensive operations. The EJB container might occasionally write a stateful session bean to secondary storage. However, stateless session beans are never written to secondary storage. To support the same number of clients, an application typically requires fewer stateless session beans than stateful session beans. Whenever possible, choose stateless session beans instead of stateful session beans.

A client should explicitly remove a stateful session bean by calling the remove() method of the component interface. Otherwise, the container keeps the stateful bean until it times out. This wastes resources such as memory, secondary storage, ...

Get Sams Teach Yourself EJB in 21 Days 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.