Is there a way to programatically track the size of a particular session on a Java EE app server, or do I have to resort to the app server’s vendor specific instrumentation to do this?
Two scenarios:
- Track from within the application (a sort of JMX-type interface)
- Track from without (outside) – a generic piece of code that works on all app servers.
There isn’t a standard way todo this. In fact there isn’t actually a particularly good way to weigh an Object, assuming it’s more than just primatives. One way to is to serialise the object to a byte array and take that as an indicator of the size.
An option would be to use a profiler like YourKit switch makes a pretty good stab at calculating the retained size of a reference.
There maybe Vendor specific API’s for this as most SessionManager’s have to serialise the session data for replication and persistence.