zoukankan      html  css  js  c++  java
  • 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失败");
            }
  • 相关阅读:
    Mecanim分析
    Mecanim 动作复用示例
    Unity3D FPS帧数修改
    Unity游戏暂停之Update与FixedUpdate区别
    我对程序开发流程的理解
    Zygote进程【1】——Zygote的诞生
    Android之SDK、NDK、JNI和so文件
    Android的4种文件类型Java,class,dex,apk
    android系统架构解析
    Android ART运行时与Dalvik虚拟机
  • 原文地址:https://www.cnblogs.com/miaoying/p/11227519.html
Copyright © 2011-2022 走看看