JVM参数设置
-Xloggc:./gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps
工程启动慢与年轻代GC频繁无关
jmap -dump:format=b,file=./heap.hprof 进程号
结果:没有发现有个别大对象占用大量内存的情况
[2021-09-03 10:42:58.668] - [INFO] - [main] - [org.springframework.aop.framework.CglibAopProxy] - Unable to proxy interface-implementing method [public final java.util.List com.epoch.bdp.util.service.excel.AbstractExcelProcess.getExcelHeader(com.epoch.bdp.util.service.excel.context.ExcelProcessContext)] because it is marked as final: Consider using interface-based JDK proxies instead!
结论:部分被代理类因为类中有final修饰的方法,无法被cglib进行代理
这里主要涉及的启动参数设置是下面两个:
springboot2.2以后支持配置全局懒加载机制,springboot2.2以前实现BeanFactoryPostProcessor 类。
但是存在以下问题:
package com.epoch.boot.config; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.stereotype.Component; import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; /** * 〈一句话功能简述〉 * * @author 刘建宇 * @since ECS2.0 */ @Component public class BeanInitCostTimeBeanPostProcessor implements BeanPostProcessor { private static final Logger logger = LoggerFactory.getLogger(BeanInitCostTimeBeanPostProcessor.class); private static final ConcurrentHashMap<String, Long> START_TIME = new ConcurrentHashMap<>(); @Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { START_TIME.put(beanName, System.currentTimeMillis()); return bean; } @Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if(Objects.nonNull(START_TIME.get(beanName))){ long costTime = System.currentTimeMillis() - START_TIME.get(beanName); if(costTime>300) { logger.error("beanName:{},cost:{}",beanName,costTime); } } START_TIME.clear(); return bean; } }
结论:发现有个别对象初始化时占用时间较长
注解说明
@Target({ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented @Import({AspectJAutoProxyRegistrar.class}) public @interface EnableAspectJAutoProxy { // true:使用cglib代理,false:使用jdk代理 boolean proxyTargetClass() default false; // 控制代理的暴露方式,解决内部调用不能使用代理的场景,默认为false. boolean exposeProxy() default false; }
最后判断结果为:因为项目中配置了大量AOP切面类,严重影响了启动速度