0
votes

As per the oracle documentation...

Singleton session beans offer similar functionality to stateless session beans but differ from them in that there is only one singleton session bean per application, as opposed to a pool of stateless session beans, any of which may respond to a client request. Like stateless session beans, singleton session beans can implement web service endpoints.

Singleton session beans maintain their state between client invocations but are not required to maintain their state across server crashes or shutdowns.

Why Singleton session beans are mainting their state between client invocations? As far as I know, stateless/singleton both should be cleaned once invocation completes! Please explain.

2

2 Answers

1
votes

You are confusing the paragraph. It says that singleton session beans offer similar functionality to Stateless session beans. It doesn't say that they are stateless. Where did you get the information that Singletons have to be cleaned between invocations? That's untrue. The one reason to use a singleton in your application is so that you can save the state and have it consistent across the application. examples of where singletons can be used are in Logging or for storing application wide config information. see the wikipedia page for more information.

2
votes

The answer is in your post is probably a paragraph above from where you got your quote. Its one instance per application. It follows the singleton pattern ...

http://docs.oracle.com/javaee/6/tutorial/doc/gipjg.html#gipim

Singleton Session Beans A singleton session bean is instantiated once per application and exists for the lifecycle of the application. Singleton session beans are designed for circumstances in which a single enterprise bean instance is shared across and concurrently accessed by clients.

Singleton session beans offer similar functionality to stateless session beans but differ from them in that there is only one singleton session bean per application, as opposed to a pool of stateless session beans, any of which may respond to a client request. Like stateless session beans, singleton session beans can implement web service endpoints.

Singleton session beans maintain their state between client invocations but are not required to maintain their state across server crashes or shutdowns.

Applications that use a singleton session bean may specify that the singleton should be instantiated upon application startup, which allows the singleton to perform initialization tasks for the application. The singleton may perform cleanup tasks on application shutdown as well, because the singleton will operate throughout the lifecycle of the application.