2013-07-18 131 views
0

我想知道java中的System.setProperty是否会导致为整个JVM设置属性。因此,如果我在方法中设置此属性,将为Weblogic服务器中的整个JVM设置属性。java中的系统属性

+0

[Java系统属性的范围]的可能重复(http://stackoverflow.com/questions/908903/scope-of-the-java-system-properties) –

+1

简短答案是肯定的......假设你实际上只谈论一个JVM而不是多个JVM。阅读链接的问答 –

回答

1

YES

java.lang.System中#的setProperty源代码:

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); 
} 

props仅在java.lang.System私人静态成员。

private static Properties props; 

所以,java.lang.System#setPropertyjava.lang.System#getProperty只是普通的静态方法。更改props会影响整个JVM。