Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase the cache size for Integer object

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.

like image 641
sparsh610 Avatar asked Sep 02 '25 05:09

sparsh610


1 Answers

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.

like image 178
SMA Avatar answered Sep 04 '25 18:09

SMA