更改JVM的参数 [英] On change the arguments of JVM

查看:86
本文介绍了更改JVM的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我想更改JVM的一些参数,以便可以更改Integer值的缓存,但是出现了一些问题:


源代码:


Recently,I want change some arguments of JVM so that I can change the cache for Integer value , but some problems have appeared:


Sourse code:


public class test {

	public static void main(String[] args) {
		Integer i1=300;
		Integer i2=300;
		System.out.println(i1==i2);
	}

}

如果我使用"java测试"运行此过程,通常它将显示"false".

详细信息:

1:javac test.java
2:jvva -server test.java
3:java -Djava.lang.Integer.IntegerCache.high = 200测试
4:java -server -Djava.lang.Integer.IntegerCache.high = 200 test
5:java -XX:AutoBoxCacheMax = 200测试
6:java-服务器-XX:AutoBoxCacheMax = 200测试
7:java-服务器-XX:+ AggressiveOpts测试

当我更改所有参数时,它应该显示为"false",但令我惊讶的是,它应该为"true".我知道
如果i1是100而i2是100,那么我使用"java测试"来运行此过程,以获得"true"的结果,因为它们是
在-128〜127之间.如果i1为200而i2为200,则结果将为"false",因为它们超出了
的范围 -128〜127,但是当我将最终变量的高电平更改为200时,结果将为"true".所以所有的结论
在你上面认为正确,好吗?但是现在,我又做了一次更改,i1是300,i2是300,我只保留值
最终变量high(200)的值,为什么最后它应该为"true"? Cuz i1和i2超出了-128〜200的范围,因此
它有什么问题?

If I use "java test" to run this procejure , and normally it will print "false".

Details:

1:javac test.java
2:jvva -server test.java
3:java -Djava.lang.Integer.IntegerCache.high=200 test
4:java -server -Djava.lang.Integer.IntegerCache.high=200 test
5:java -XX:AutoBoxCacheMax=200 test
6:java -server -XX:AutoBoxCacheMax=200 test
7:java -server -XX:+AggressiveOpts test

And when I changed all the arguments and it should print "false" , but to my surprise it should be "true" . And I know
if i1 is 100 and i2 is 100 , then I use "java test" to run this procejure getting the result of "true" cuz they are
between -128~127 . And if i1 is 200 and i2 is 200 , then the result will be "false" cuz they are beyond the rainge of
-128~127 , however when I change the final varible high to 200 , the result will be "true" . So all the conclusion
above you think right , ok ? But now , I have made a change again , i1 is 300 and i2 is 300 , and I just keep the value
of final varible high(200) , and why it should be "true" at last ? Cuz i1 and i2 are beyond the rainge of -128~200 , so
what is the problem with it ?

推荐答案

在您的示例中,您将两个对象都分配给同一实例.与String一样,如果使用文字,它将始终是同一实例.如果使用new Integer(300),它将保证唯一的实例.
In your example, you are assigning both objects to the same instance. As with String, if you use a literal it will ALWAYS be the same instance. If you used new Integer(300) it would guarantee unique instances.


这篇关于更改JVM的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆