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

When postgresql new batch of data, the amount of data bulk insert too much, resulting in abnormal IO

Can only put so much data is first divided and then bulk insert, but the feeling in this way is not the optimal solution, temporarily wore specific List segmentation is as follows:

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;
    }
}

Where the original call volume to be treated:

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

 

Guess you like

Origin www.cnblogs.com/miaoying/p/11227519.html