当前位置:   article > 正文

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

an /0 eror ocumred while sendin to the hackend

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失败");
        }

 

转载于:https://www.cnblogs.com/miaoying/p/11227519.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/483647
推荐阅读
相关标签
  

闽ICP备14008679号