| Are the Container's statistics object counters wrong? |
|
Scenario:I have a stateful session bean. I invoke some business method on the bean. I look at the server and it shows (after 5 seconds) "PASSIVE 1, Total in Memory 1". My client sleeps for 5 seconds and invokes the same business method. The server reports, "PASSIVE 2, Total In Memory 2"--isn't that strange? Each time I call the method, the EJB Container’s counters are bumped. Is this correct? I expected that there would be only one instance because I am working on the same one object.ExplanationIn fact, the number of created objects do NOT increase. The objects are being Activated and Passivated. This may account for the thinking that the "counters are out" when the objects are being Activated and Passivated.There are two situations where a session bean is created:
A new object is created in both cases. However, in the second case, the object's constructor is not called. Thus, there are two situations where an object is created, but only one situations where it is constructed. Just because the container releases the instance does not mean that the VM garbage collects the instance. We distinguish these counts by "total in memory" (how many are in memory, including both ones that we have references to, and ones that we don't), and "total in use" which is only the count of the number of beans we are hanging on to. It is up to the garbage collector to reduce the "total in memory" down to the "total in use" at its discretion. Basically the GC typically only fires when the VM gets low on memory so, for mostly idle clients, this does not occur very often. There is still a bug in the counters whereby the PASSIVE count is not reliable. You should ignore this counter.
|