• PSQLException: An I/O error occurred while sending to the backend.


    postgresql批量新增数据时,批量插入的数据量太大了,造成了IO异常

    只能把这么多数据先进行分割,再批量插入,但是感觉这种方式不是最优解,先暂时顶着,具体List分割方式如下:

    package cn.ucmed.otaka.healthcare.cloud.util;
    
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    
    public class PartitionArray<T> {
    
        public Map<Integer, List<T>> partition(List<T> tArray, int capacity) {
            if (tArray.isEmpty() || capacity < 1) {
                return null;
            }
            Map<Integer, List<T>> result = new HashMap<>();
    
            int size = tArray.size();
            int count = ((Double) Math.ceil(size * 1.0 / capacity)).intValue();
    
            for (int i = 0; i < count; i++) {
                int end = capacity * (i + 1);
                if (end > size) end = size;
                result.put(i, tArray.subList(capacity * i, end));
            }
            return result;
        }
    }

    原先批量调用的地方做个处理:

            try {
                PartitionArray<MDynamicFuncReleaseHistory> partitionArray = new PartitionArray<>();
                Map<Integer, List<MDynamicFuncReleaseHistory>> batchList = partitionArray.partition(releaseHistoryList, INSERT_CAPACITY);
                batchList.forEach((k, v) -> {
                    mDynamicFuncReleaseHistoryMapper.batchInsert(v);
                });
            } catch (Exception e) {
                log.error(e.getMessage());
                throw new BusinessException(500, "新增MDynamicFuncReleaseHistory失败");
            }
  • 相关阅读:
    微信小程序---app.json中设置背景色不生效解决办法
    给网站设置ICO图标
    ajax事件(五)
    ajax关于主流中的异类:应对Opera(四)
    dashboard
    tomcat 清理日志
    jQuery datatable
    php wampserver 80 端口无法开启的解决方法
    mysql 行列转换
    jQuery-2.1.4.min.js:4 Uncaught TypeError: Illegal invocation
  • 原文地址:https://www.cnblogs.com/miaoying/p/11227519.html
Copyright © 2020-2023  润新知