When you want light isolation of "System Properties" by ClassLoader in a retrocompatible way... SystemClassLoaderProperties provides Hierarchical Properties associated to a ClassLoader, maintaining the behavior of standard System.getProperty. Open Source Java project under Apache License v2.0
Current Stable Version is 1.0.0
public static void main(final String[] args) { // Install SystemClassLoaderProperties SystemClassLoaderProperties.getInstance().takeover(); // Normal Usage System.setProperty("xxxxx", "value"); System.out.println(System.getProperty("xxxxx")); }
Usage Example in a standalone Java application (using a JavaAgent)
java -javaagent:<directory>/lib/systemclassloaderproperties-x.x.x.jar com.acme.YourClass
Usage Example in a Tomcat (using a JavaAgent)
# tomcat/bin/setenv.sh CATALINA_OPTS="$CATALINA_OPTS -javaagent:<directory>/lib/systemclassloaderproperties-x.x.x.jar"
// Bootstrap // | // System // | // Common // / \ // Webapp1 Webapp2
<% // One counter by each Webapp Integer x = Integer.valueOf(System.getProperty("dummy.test", "0"))+1; out.print(getClass().getClassLoader() + ":" + System.setProperty("dummy.test", String.valueOf(x))); %>
for j in a b c; do { for i in 1 2; do { curl http://localhost:8080/Webapp${i}/test.jsp } done } done
org.apache.jasper.servlet.JasperLoader@7064ce:null
org.apache.jasper.servlet.JasperLoader@7df6d9:null
org.apache.jasper.servlet.JasperLoader@7064ce:1
org.apache.jasper.servlet.JasperLoader@7df6d9:1
org.apache.jasper.servlet.JasperLoader@7064ce:2
org.apache.jasper.servlet.JasperLoader@7df6d9:2
Note about Security: You may need a SecurityManager if you want strong security (this "light isolation" can be easily circumvented in a hostile environment).
<dependency>
<groupId>org.javastack</groupId>
<artifactId>systemclassloaderproperties</artifactId>
<version>1.0.0</version>
</dependency>
Inspired in ClassLoader, this code is Java-minimalistic version.