MetaSpace浅析

jdk1.8后 使用metaSpace代替了永久代
我们在使用metaSpace会设置两个参数:
官网java8相关参数

-XX:MetaspaceSize=size

含义:当metaspace达到size值时,触发fullgc

Sets the size of the allocated class metadata space that will trigger a garbage collection the first time it is exceeded. This threshold for a garbage collection is increased or decreased depending on the amount of metadata used. The default size depends on the platform.

-XX:MaxMetaspaceSize=size

含义:metaspace的最大值

Sets the maximum amount of native memory that can be allocated for class metadata. By default, the size is not limited. The amount of metadata for an application depends on the application itself, other running applications, and the amount of memory available on the system.

如果项目启动时加载的类过多,metaspaceSize又使用了默认值或者值很小,会导致启动时就会fullgc
启动后项目如果频繁的进行类加载,也会导致metaspace达到触发fullgc的阈值,max值太小甚至会发生oom
所以建议metaspaceSize 设置和max一致 通过观察项目实际使用情况做调整

猜你喜欢

转载自blog.csdn.net/lbh199466/article/details/105538079