关于后端:性能调优及MyBatis开启batch模式

针对我的项目中性能调优总结有如下几条:

  1. 防止服务间的屡次调用,可将屡次批改为一次,对于查问业务,如业务不容许则可将业务数据进行缓存(代码或者redis进行缓存)。
  2. 服务间调用对于无需返回并且对数据准确性后果较弱的操作,尝试批改为异步,尽快开释连贯。
  3. 批改操作及删除操作条件必须明确,防止独自应用主键,例如加上区划,年度,单位等。
  4. 禁止应用new Runable(), 应用线程必须应用线程池明确最小,最大线程数。
  5. 单次插入数据量特地大,字段特地多,业务的使用量
    具体写法如下图:

@Autowired
private SqlSessionTemplate sqlSessionTemplate;
public void test(List insertList){
SqlSessionFactory sqlSessionFactory = sqlSessionTemplate.getSqlSessionFactory();
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
try {
    GlaBalanceDao blDao = sqlSession.getMapper(GlaBalanceDao.class);
    insertList.stream().forEach(bal->{
        blDao.insert(bal);
    });
    sqlSession.clearCache();
    sqlSession.commit();
}catch(Exception e){
    throw new RuntimeException(e);
}finally {
    sqlSession.close();
}
}

开启mybatis batch模式源码解析:

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理