Quote from EJB 3.1 Specification
4.7 Beans Inactive Session
The idle bean segment is a beans session whose instances have a non-interactive state. This means that all instances of the bean are equivalent if they are not involved in servicing the method called by the client.
The term "idle" means that the instance has no state for a particular client . However, instance instance variables may contain the status of call calls caused by the client.
Examples of such state include an open database connection and an object reference for a bean.
The emphasis is on the lack of dialogue state . They may have a “different” state.
For example, I used it to check whether the load was distributed equally across all instances of the node cluster:
@Stateless(name = "DemoPingSb") @Remote(DemoPingSbIfc.class) public class DemoPingSb implements Serializable, DemoPingSbIfc { private final AtomicInteger instancePingCount = new AtomicInteger(0); private final static AtomicInteger classPingCount = new AtomicInteger(0); public DemoPingSb() { super(); } public String ping(final String s) { final int local = this.instancePingCount.incrementAndGet(); final int global = classPingCount.incrementAndGet(); System.out.println("INFO: local " + local + ", global " + global + ", s " + s); return s.toUpperCase(); } }
and if there is sufficient load:
13: 13: 21,769 INFO [stdout] (http-localhost-127.0.0.1-8080-1) INFO: local 22, global 22, s hello
13: 13: 21,936 INFO [stdout] (http-localhost-127.0.0.1-8080-1) INFO: local 1, global 23, s hello
So, there are some special cases when this function can be useful.
Note
- The specification speaks of instance variables; the use of static variables is not considered there. Thus, the code may be incorrect in relation to
classPingCount - Using
AtomicInteger for instancePingCount can be replaced with volatile int , because (4.10.13)
A container must ensure that only one thread can execute a session without a state or bean instance at any time.
- A session without a bean is never passivated (4.2)
Beryllium
source share