Welcome!

Java Authors: Roger Strukhoff, Ian Khan, Fiona McNeill, Elizabeth White, Pat Romanski

Related Topics: Java, Virtualization, AJAX & REA

Java: Blog Post

How to Monitor JVM System Properties

Trace all calls to System.getProperty method

Many libraries use system properties for settings. For example, you usually have to set a property to enable debug traces or to activate certain behaviors. However, sometimes system properties that are used are not well documented or you are not sure that they are having some effect. In such cases it would be useful to have a way to know which system properties are queried.

There are several manners to do this but I have found a simple way that is not so intrusive. By creating a custom Security Manager you can define a method that checks property accesses. This method is able to send to the logger or to the standard output what property has been queried.

public class PropertyAccessPrinterSecurityManager extends SecurityManager {
	@Override
	public void checkPropertyAccess(String key) {
		System.out.println("System.getProperty(\""+key+"\")");
	}
}

 

This article explains how to know which JVM System Properties are actually being queried by libraries. This class should be compiled and available in the classpath.

Now we create in the current directory a file named “java.policy” with the following content:

grant {
	permission java.security.AllPermission;
};

 

We just have everything we need to trace calls to System.getProperty. Next we add these parameters to the java call:

java -Djava.security.manager=PropertyAccessPrinterSecurityManager -Djava.security.policy==java.policy

 

More Stories By Alfredo Diaz

Alfredo Diaz is a Java EE Architect with over 10 years of experience. He is an expert in SOA, real-time processing, scalability and HA. He is an Agile enthusiast.