在研究一些源码的时候,会发现,源码中有时会通过VM.getSavedProperty获取一些参数,我们平时写应用时,获取系统参数的时候,通常是使用System.getProperty,那VM.getSavedProperty和System.getProperty区别是什么呢?
在System的initializeSystemClass方法中,会初始化系统参数,初始化系统参数的时候:
1、首先获取所有的系统参数放在System中
2、有一些可由VM选项控制的系统配置,例如直接内存的最大数量和用于支持自动装箱的对象标识语义的整数缓存大小。 通常,该库将从VM设置的属性中获取这些值。 如果这些属性仅用于内部实现,则应从系统属性中删除这些属性。
private static void initializeSystemClass() {
// VM might invoke JNU_NewStringPlatform() to set those encoding
// sensitive properties (user.home, user.name, boot.class.path, etc.)
// during "props" initialization, in which it may need access, via
// System.getProperty(), to the related system encoding property that
// have been initialized (put into "props") at early stage of the
// initialization. So make sure the "props" is available at the
// very beginning of the initialization and all system properties to
// be put into it directly.
props = new Properties();
//初始化系统参数
initProperties(props); // initialized by the VM
// There are certain system configurations that may be controlled by
// VM options such as the maximum amount of direct memory and
// Integer cache size used to support the object identity semantics
// of autoboxing. Typically, the library will obtain these values
// from the properties set by the VM. If the properties are for
// internal implementation use only, these properties should be
// remov

最低0.47元/天 解锁文章
596





