Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scope of System.setProperty in Tomcat

This question is "cousin" of this one involving Android. But here we are in Tomcat environment.

If in my webapp I set a property with System.setProperty("property_name", "property_value");, which scope will it be applied to?

  • all JVM in this machine
  • all Tomcat webapps
  • only the webapp that executes the instruction
  • only the thread that executes the instruction
  • something else...

Many thanks!

like image 670
bluish Avatar asked Sep 29 '11 13:09

bluish


2 Answers

A system property has a JVM scope. The property will thus be modified (and available) in the whole tomcat JVM, for all the webapps and for Tomcat itself.

Note that the system property is stored in memory, and will thus not persist if you stop and restart Tomcat.

like image 146
JB Nizet Avatar answered Nov 02 '22 22:11

JB Nizet


In Java System.setProperty() always applies to the entire JVM.

So yes, it will affect the whole Tomcat instance, including all webapps.

like image 41
Joachim Sauer Avatar answered Nov 02 '22 23:11

Joachim Sauer