关于java.security.AccessController.doPrivileged
lineSeparator = (String) java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("line.separator"));
}
比较好奇和System.getProperty有什么区别呢?
下面是stackoverflow上的回答http://stackoverflow.com/questions/4954924/getpropertyaction-vs-system-getproperty-in-obtaining-system-variables
感觉也没有完全说清楚。
关于System.getProperty 看源码得到:
public static String getProperty(String key) {
checkKey(key);
SecurityManager sm = getSecurityManager();
if (sm != null) {
sm.checkPropertyAccess(key);
}
return props.getProperty(key);
}
再得到set的方法:
public static void setProperties(Properties props) {
SecurityManager sm = getSecurityManager();
if (sm != null) {
sm.checkPropertiesAccess();
}
if (props == null) {
props = new Properties();
initProperties(props);
}
System.props = props;
}
可以看到时需要initProperties
private static native Properties initProperties(Properties props);
然后就终结了 这个native 的方法是怎么做的呢 不知道。。。
而且doPrivileged也还是native 的方法 关于这两个native 的方法的区别真的就是不知道了。