A recent question on the CF-Talk lists had been asked several times in the past, so I thought I’d post some basic code routines for accessing parts of the Java engine via ColdFusion.
<cfscript>
sys = createobject("java", "java.lang.System");
// Set a system property
sys.setProperty('myProperty', 'myPropertyValue');
// Assign local variable to properties structure
props = sys.properties;
</cfscript>
<cfdump var="#props#">
<cfscript>
sessiontrackerObj= createObject("java","coldfusion.runtime.SessionTracker");
activesessions = sessiontrackerObj.getSessionCollection(application.applicationname);
nosessions=ListLen(structkeyList(activeSessions));
</cfscript>
<cfoutput>
<h3>Total Sessions : #nosessions#</h3>
</cfoutput>
<cfdump var="#activesessions#">
* Courtesy of Snake’s Blog
<cfscript>
// Create Java object instances needed for creating memory charts
runtime = createobject("java", "java.lang.Runtime");
mgmtFactory = createobject("java", "java.lang.management.ManagementFactory");
pools = mgmtFactory.getMemoryPoolMXBeans();
maxJVM = runtime.getRuntime().maxMemory();
freeJVM = runtime.getRuntime().freeMemory();
newGeneration = pools[2].getUsage().getUsed();
survivorspace = pools[3].getUsage().getUsed();
tenuredGeneration = pools[4].getUsage().getUsed();
permanentGeneration = pools[5].getUsage().getUsed();
</cfscript>
3 Responses for "Java Subsystem Access Via ColdFusion"
Hi, the Java Memory Usage scripts gives me this error: “Class not found: java.lang.management.ManagementFactory “.
Does this require the 1.5 JDK? If not, how do I get and load that class for the 1.4 JDK?
thank you,
Chris
Chris, yes the ManagementFactory is only in JDK 1.5 or greater. It won’t work in any previous JDK releases.
Thanks. I appreciate the quick response!
Can I run the 1.5 JDK on my desktop and probe a JVM that’s version 1.4?
Leave a reply