Java basic frequency interval data type of packaging data cache

A, Java basic data type of packaging: Integer, Long, Double, Float, Boolean, Byte, Short, Character.

Second, the high-frequency buffer

  • Double and Float in which no cache, there are other types of high-frequency buffer zone. High-frequency range of the cache buffer section is:
    Boolean: using static final, it will return a static value
    Byte: 127 -128 ~
    Short: 127 -128 ~
    Character: 0 ~ 127
    Long: 127 -128 ~
    Integer: -128 ~ 127

  • If the value is used for packaging in this buffer zone, the complex will be the direct use of an existing object, the cache values outside the interval will be re-generated on the heap. Therefore, in determining whether or not to use equal, "==", with equals, otherwise, the following occurs:
    Integer I1 = 127;
    Integer i2 = 127;
    I1 i2 == -> to true

    Integer i3 = 128;
    Integer i4 = 128;
    i3 == i4 ->false
  • Integer modified cache is the only one range of packaging. Add parameters in VM options: -XX: AutoBoxCacheMax = 555 maximum range is about to change the cache 555.

Guess you like

Origin blog.51cto.com/14305934/2432216