My previous post about a ColdFusion Server scope enhancer provided a chunk of code that you could include somewhere in your application to provide much more detailed information about the state and properties of your Java application server.

In an effort to clean up that code and make it perform slightly faster, I created a Java library that you can now include in your ColdFusion web application’s WEB-INF\lib directory.
Scope Enhancer Location

This makes the code much more simple to read and maintain. Here’s an example call to enhance your Server scope.

<cfscript>
runtime = createobject("java", "java.lang.Runtime");
enhancer = createobject("java", "orbwave.ScopeEnhancer");
mgmtFactory = createobject("java", "java.lang.management.ManagementFactory");
sys = createobject("java", "java.lang.System");

memoryPoolBean = mgmtFactory.MemoryPoolMXBeans;

server.jvm = StructNew();
server.jvm.memory = StructNew();
server.jvm.memory.pools = enhancer.memoryPools();
server.jvm.memory.free = runtime.getRuntime().freeMemory();
server.jvm.memory.max = runtime.getRuntime().maxMemory();

server.jvm.arguments = mgmtFactory.RuntimeMXBean.getInputArguments();
server.jvm.threads = enhancer.serverThreads();
server.jvm.properties = enhancer.systemProperties();

server.os.environmentVariables = enhancer.environmentVariables();
</cfscript>

There is one major difference between using the ColdFusion code version and the new Java library, and that is that the jvm.memory.pools and jvm.threads keys were queries in the CF version but are now structures in the Java version.

One addition was made in the new library and that is the os.environmentVariables key that holds all of the environment variables of your operating system.
evars.gif

Steps to install

  1. Download enhancer.jar library
  2. Put the enhancer.jar file in your web application’s WEB-INF\lib directory.
  3. Restart your Java application server
  4. Copy the code shown above into application (for example, your onApplicationStart event in Application.cfc)

Now all of the information is available for your use. Once again, you’ll need to be running at least the 1.5 JDK for this to work.