4

While reading this question

I come to know that we can increase the size of cache through this comment

The recent version of Java 6 support changing the maximum cache value to greater than 127

I google it but didnt find to do same.

Please help.

Community
  • 1
  • 1
sparsh610
  • 1,552
  • 3
  • 27
  • 66

1 Answers1

5

IntegerCache for e.g. says this:

/**
 * Cache to support the object identity semantics of autoboxing for values between 
 * -128 and 127 (inclusive) as required by JLS.
 *
 * The cache is initialized on first usage. During VM initialization the
 * getAndRemoveCacheProperties method may be used to get and remove any system
 * properites that configure the cache size. At this time, the size of the
 * cache may be controlled by the vm option -XX:AutoBoxCacheMax=<size>.

So either you use VM parameter or you use System property like:

-Djava.lang.Integer.IntegerCache.high=256

When launching the JVM.

SMA
  • 36,381
  • 8
  • 49
  • 73
  • where I need to define `-Djava.lang.Integer.IntegerCache.high=256`. – sparsh610 May 16 '15 at 15:06
  • While launching jvm like `java -Djava.lang.Integer.IntegerCache.high=256 MymainClass` – SMA May 16 '15 at 15:06
  • i am using eclipse :( how to do this in eclipse – sparsh610 May 16 '15 at 15:08
  • Either in the run configuration you use to launch you class (VM arguments) or in the argument in the JRE definition (in the preferences, find where the JRE are defined, you can have JVM variables set for all runs on that JRE). – JP Moresmau May 16 '15 at 15:11
  • run as -> run configuration -> arguments -> vm arguments -> paste -Djava.lang.Integer.IntegerCache.high=256 – SMA May 16 '15 at 15:12