why stateless session bean mainting state between method calls
If I have an instance var in a stateless session bean and in a certain remote method I change its value then I call the next method keeping the same remote refrence. it got changed values that means instance state is maintained between the method calls.
This is the behaviour as mentioned in EJB specification 1.1 topic 6.8. it also specifies that this behaviour is not confirmed. it is possible that Container may delegate the requests from the same client within the same transaction to different instances.
So I beleave that we should not allow client to update the value of instance var in any method at any time of the life cycle.
If this is the case then why specification does not enforce that every instance var of stateless session bean should be 'final'.
I would like to have comments.
Thanks
Ultimately the bean instance running inside the container is a Java object, which can have instance fields like any other. Hence if you change a field in one method call and inspect the field in the next method call then you will see a changed value. The point is with Stateless Session EJBs you are not guaranteed to get the same object. That does not mean that you won't - only that you should not depend on it.
Obviously in this case, making two method calls in quick succession, the EJB receiving the calls was the same Object.
A stateless session bean can't maintain client state. It means that any client calls the bean method will reset the bean state. Maybe in ur case, no other clients call the bean between ur calls on the bean. If u do the following test, u will find the stateless SB feature:
class Tester...{
...
SLSBean b = home.create();
b1.add(10);
//try to wait some time, let secont client call the bean
...
System.out.println(b1.get());
...
}
class SLSBean ...{
int a;
void add(int i){ a += i;}
int get(){ return a;}
....
}
When u build the test class, u should make two client threads and make sure the second client create a bean instance just between the first client calls. u will find the answer.