Scope of System.setProperty in Tomcat

独自空忆成欢 提交于 2020-01-14 07:37:08

问题


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!


回答1:


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.




回答2:


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

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



来源:https://stackoverflow.com/questions/7597925/scope-of-system-setproperty-in-tomcat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!