Basically, there’s this Java Interface, OperatingSystemMXBean, that will tell you the server’s Total Physical Memory, and the server’s Free Physical Memory.
It goes like this:
<cfset mf = createObject("java", "java.lang.management.ManagementFactory")> <cfset osbean = mf.getOperatingSystemMXBean()> <cfoutput> free physical mem = #osbean.getFreePhysicalMemorySize()#<br/> total physical mem = #osbean.getTotalPhysicalMemorySize()#<br/> </cfoutput>
I find this interesting because my production server is recently starting to act up… every once in a while is reporting memory full on the JVM. While I figure out the reasons, I need to perform a garbage collection every now and then. Using this little script, I can create a Scheduled Task that periodically checks on the memory consumption, and whenever it reaches some limit, I want it to trigger the G.C.
About the G.C., here it is:
<cfset obj = createObject("java","java.lang.System")/>
<cfset obj.gc()/>
<cfset obj.runFinalization()/>
It does work to keep the server running, but I still need to find that memory leak.
No comments:
Post a Comment