Hi,
I am new to Java EE and EJB 3, so many concepts are not clear to me.
I've read somewhere that
Stateless beans in Java do not keep their state between two calls from the client, unlike Stateful session beans which do keep state.
I created my first bean, I first used @Stateless annotation and then @stateful annotation, and it seems it is having the same behavior.
This is the session bean:
@Stateless
public class HelloWorldBean implements IHelloWorldLocal {
private int number = 1;
@Override
public int add(Integer number) {
this.number += number;
return this.number;
}
}
I wrote a servlet to invoke session bean add method this way:
out.println("The result is " + helloWorld.add(2));
out.println("The result is " + helloWorld.add(3));
out.println("The result is " + helloWorld.add(4));
The results after these three invocations are 3, 6, 10. As far as I am concerned, results should be 3, 4 and 5 based on the concept that the Stateless beans don't keep state.
If I switch this bean to be a Stateful one, I get the same results.
What have I missed here?
Thanks in advance for your time and help.