1

I want to know if System.setProperty in java will cause the property to be set for the entire JVM.So if I set this property in a method will that be set for the entire JVM in a weblogic server.

Ashok Ambrose
  • 191
  • 3
  • 17
  • possible duplicate of [Scope of the Java System Properties](http://stackoverflow.com/questions/908903/scope-of-the-java-system-properties) – Brian Roach Jul 18 '13 at 22:38
  • 1
    The short answer is yes ... assuming that you are really talking about just one JVM and not multiple JVMs. Read the linked Q&A – Stephen C Jul 18 '13 at 22:40

1 Answers1

1

YES

java.lang.System#setProperty source code:

public static String setProperty(String key, String value) {
    checkKey(key);
    SecurityManager sm = getSecurityManager();
        if (sm != null) {
        sm.checkPermission(new PropertyPermission(key,
        SecurityConstants.PROPERTY_WRITE_ACTION));
    }

    return (String) props.setProperty(key, value);
}

and props is only a private static member in java.lang.System.

private static Properties props;

So, java.lang.System#setProperty and java.lang.System#getProperty are just normal static methods. Change the props will affect the whole JVM.

lichengwu
  • 4,277
  • 6
  • 29
  • 42