Best Practices

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, and so on.

Stateful session beans cannot be shared among different clients. A multithreaded client (such as a servlet or a Swing application) must serialize all its calls to the stateful session bean. Simultaneous access to a stateful session bean results in a java.rmi.RemoteException exception.

Consider tuning the stateful session bean's instance cache size. For best performance, the maximum number of beans in the cache should be equal to maximum number of concurrent clients. If the cache ...

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.