zoukankan      html  css  js  c++  java
  • springBoot事务失效导致批量插入性能巨幅降低

        @Override
        public void savePatientAndSeekMedical(){
            long start = System.currentTimeMillis();
    //        ((PatientService) AopContext.currentProxy()).saveBatch(patients, 1000);
    //        saveBatch(patients, 1000);
            SpringUtil.getBean(this.getClass()).saveBatch(patients, 1000);
    //        patientMapper.saveBatchBySql(patients);
    //        seekMedicalService.saveBatch(seekMedicals, 1000);
            log.warn("保存" + patients.size() + "条患者数据,用时:" + (System.currentTimeMillis() - start) + "ms");
            patients.clear();
            seekMedicals.clear();
        }

    这段代码里面使用了三种方式保存患者数据

    第一种 ((PatientService) AopContext.currentProxy()).saveBatch(patients, 1000); 方式在这里会抛出Cannot find current proxy: Set 'exposeProxy' property on Advised to 'true' to make it available异常,猜测原因是saveBatch是mybatisPlus的方法,普通情况如果需要在在该方法上做切面可以用该方式

    第二种 saveBatch(patients, 1000); 会导致性能巨慢 导入2w调数据需要900秒左右

    第三种 SpringUtil.getBean(this.getClass()).saveBatch(patients, 1000); 可以保证事务并且性能非常好(2w条数据大概15秒左右)

    贴上SpringUtil代码

    package cn.rivamed.fhvc.util;
    
    import org.springframework.beans.BeansException;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.ApplicationContextAware;
    import org.springframework.core.env.Environment;
    import org.springframework.stereotype.Component;
    
    @Component
    public class SpringUtil implements ApplicationContextAware {
    
        private static ApplicationContext applicationContext = null;
    
        @Override
        public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
            SpringUtil.applicationContext = applicationContext;
        }
    
        public static <T> T getBean(Class<T> cla) {
            return applicationContext.getBean(cla);
        }
    
        public static <T> T getBean(String name, Class<T> cal) {
            return applicationContext.getBean(name, cal);
        }
    
        public static Object getBean(String name){
            return applicationContext.getBean(name);
        }
    
        public static String getProperty(String key) {
            return applicationContext.getBean(Environment.class).getProperty(key);
        }
    }
  • 相关阅读:
    内存映射文件原理探索(转载)
    虚拟内存原理
    CSAPP-链接
    CSAPP-程序优化
    CSAPP-过程调用,数据存储,缓冲区溢出
    【数学,方差运用,暴力求解】hdu-5037 Galaxy (2014鞍山现场)
    【贪心+一点小思路】Zoj
    【几何模板加点小思路】hdu-4998 Rotate
    【背包问题】【出来混总是要还的...】总结+入门练手题
    【优先队列】【最近连STL都写不出来了/(ㄒoㄒ)/~~】hdu_5360/多校#6_1008
  • 原文地址:https://www.cnblogs.com/guanxiaohe/p/11818372.html
Copyright © 2011-2022 走看看