34
I would like to know the difference and when to use.
- Stateful
- Stateless
34
I would like to know the difference and when to use.
42
The difference between Stateful and Stateless is that one will save the state of the objects(Stateful) and the other will recognize each request as a new request(Stateless).
Example: Internet Protocols (IP), Hyper Text Broadcast Protocol.
Perks:
Disadvantages:
Example: Java:Httpsession, APS.net: Session
Perks:
Disadvantages:
2
Oracle JAVA EE 6 documentation regarding:
Stateful Session Beans
The state of an Object consists of the values of its instance variables. In a stateful Session bean, the instance variables represent the state of a Unique client/bean Session. Because the client interacts ("Talks") with its bean, this state is often called the Conversational state.
Stateless Session Beans
A stateless Session bean does not maintain a Conversational state with the client. When a client invokes the methods of a stateless bean, the bean’s instance variables may contain a state specific to that client but only for the Duration of the Invocation. When the method is finished, the client-specific state should not be retained.
Very simple summary:
Utilise Stateful when you need to maintain the conversational state.
Example: In a shopping cart, where you add several items and they are items relevant only to a customer, that is, there is the need to keep the list.
Utilise Stateless when there is no need to maintain the state of values.
Example: List store products (it’s the same list for any customer, right?)
The above example is quite simple, just to illustrate the idea of stateful and stateless, the use of Ejbs is usually much more complex.
-1
As far as I know Stateful keeps the status of the object during the session. Stateless keeps it independent of the session.
Example you have a program of buying and selling dollars. In this case you can use an Sstateless service to store the data of the exchange house that contains the reservation. And another Stateful service for each user (session) buy or sell dollars. What matters here is the home exchange will need to share resources between multiple users simultaneously, so you need to maintain the state of resources.
Here’s a bigger detail: http://www.devmedia.com.br/trabalhando-com-session-beans-stateless-e-stateful/28260
So Stateless is a Singleton
? there is no risk of a new instance?
There are differences. I recommend reading the documentation: http://docs.oracle.com/javaee/6/tutorial/doc/gipjg.html#gipim. If you doubt post here I try to explain better
right, but if there are differences I believe your example is not complete...
Stateless does not share resources, for each call the instance objects have their own state until the end of the method execution. Singleton is shared in all calls to the method, so it is instance objects can be shared between calls.
That mixes people. Stateless treats each request independently. Statefull has Session to identify the user and restore the status between each request. Singleton is another bix in another layer.
Browser other questions tagged java session ejb
You are not signed in. Login or sign up in order to post.
Enlightening, cleared my doubt on this subject
– Giancarlo Abel Giulian