How to increase the cache size for an Integer object

While reading this question

I find out that we can increase the cache size through this comment

Latest Java 6 supports changing max cache value to 127

I google but haven't found one to do the same.

Please, help.

+3


source to share


1 answer


IntegerCache, for example. says the following:

/**
 * 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 are using the VM parameter or you are using the System property like:



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

      

When starting the JVM.

+5


source







All Articles