This content has been marked as final. Show 1 reply
i haven't seen the actual code which reports the mem usage in the jvm, but i have to imagine the call is cheap. based on my experience using the value to monitor jvms (both remotely and from within the jvm itself) and on the comments in the MemoryMXBean javadocs which indicate that the memory usage values are intended for "monitoring" and "load balancing" type consumption, i would have to imagine that those values are not computed using expensive operations.
that said, of course there is some additional overhead for monitoring anything in the jvm. you don't get something for nothing. even if the value itself was pre-computed, you are still making method calls and, in the case of remote monitoring, moving bytes over the network (neither of which is free).
Edited by: jtahlborn on May 1, 2012 9:00 AM