How is the state of instance variables of the idle bean saved for the next call in EJB?

I am reading the Java EE7 documentation , and here is what it says for stateless bean. I am confused by what is meant by the expression in bold below

A session without a bean does not support dialog state with the client. When a client invokes methods of a stand-alone bean, instance variables of a bean may contain a state specific to that client, but only for the duration of the call. When the method is completed, the state of the client should not be saved. However, clients can change the state of instance variables in a merged state without beans state, and this state is transferred to the next call to the merged state without saving the bean state. With the exception of the method call, all instances of the idle bean are equivalent, allowing the EJB container to assign an instance to any client. That is, a session state without a bean should be applied to all clients.

However, from this post, instance variables in a session with no beans state

A session without a bean is an object that does not have a state associated with it, but can have an instance state. It does not allow simultaneous access to the bean. The contents of instance variables are not guaranteed for all method calls. All instances of a non-bean session must be considered identical by the client.

I feel that there is a contradiction here. The docs claim (in my opinion) that the state of the instance variable is saved in subsequent calls, while the last message claims that there is no guarantee that the state is saved.

Please explain

PS: I read this post: but I did not understand the answer

instance variables in a beans stateless session

EDIT will generate the SO message above

A stand-alone Beans session (SLSB) is not tied to one client, and there is no guarantee that one client can get the same instance with every method call (some containers can create and destroy Beans with every method call session, this is a solution for a specific implementation, but instances are usually combined - and I don't mention cluster environments). In other words, although stateless Beans may have instance variables, these fields are not specific to a single client, so do not rely on them between remote calls.

+6
source share
1 answer
  • SLSBs are usually created in multiples and are hidden in a pool. Thus, multiple instances will be created for the EJB UserDataService and merged

  • When the client requests the UserDataService , the container will serve one of the empty instances. Anyone. When two clients request services from the same EJB, two separate instances will be executed

  • When a client runs with SLSB, the instance used is usually returned to the pool, not destroyed . This means that the same unique EJBs that were created when the container started could well live on the heap for the entire duration of the container. This repeats itself: The same SLSBs that were created and merged when the container first places the EJB in the service are kept alive after the containerโ€™s uptime

  • Which means (3) means that if the client in (2) set any variables in the EJB instance that he acquired from the pool, and that the EJB is returned to the pool, the next client who purchases this instance will be able to see the change made to the state of this EJB (Recall that there are a certain number of EJB instances in the pool and they loop between different clients requesting the service).

  • There is no guarantee that a specific instance of the Requesting Client's UserDataService will receive . There is no guarantee that the client from (2) will receive the same instance of UserDataService for two separate requests for this EJB. This is what is meant by some kind of interactive state. You are not guaranteed to be able to talk to the same instance of this EJB over multiple calls . This does not mean that EJBs are destroyed by the average request, just during the looping process you cannot be sure which instance your client will relate to

+9
source

Source: https://habr.com/ru/post/976589/


All Articles