zoukankan      html  css  js  c++  java
  • 原!!将集合分段处理

    /**
         * 短信集合按照 perCount分段
         * @param list
         * @return
         */

      private static final int perCount = 3000;//单次入库数量

    private List<List<OpenMsgDo>> divideIntoLists(List<OpenMsgDo> list) { if (list == null || list.size() == 0) { return null; } List<List<OpenMsgDo>> lists = new ArrayList<>(); int listSize = list.size(); int sections = listSize / perCount; int remain = listSize % perCount; int start = 0; for (int i = 1; i < sections + 1; i++) { List<OpenMsgDo> tempList = new ArrayList<>(); tempList = list.subList(start, i * perCount); lists.add(tempList); start = i * perCount; } if (remain != 0) { List<OpenMsgDo> tempList = new ArrayList<>(); tempList = list.subList(start, start + remain); lists.add(tempList); } return lists; }
    //批量入库
                for (Map.Entry<String, List<OpenMsgDo>> entry : msgMap.entrySet()) {
                    
                    String tableName = entry.getKey();
                    List<OpenMsgDo> msgList = entry.getValue();
                    //TODO 分批量插入
                    List<List<OpenMsgDo>> lists = divideIntoLists(msgList);
                    if (lists == null) {
                        continue;
                    }
                    for (int i = 0; i < lists.size(); i++) {
                        int insertRecords = msgService.batchInsertMsg(tableName, lists.get(i));
                        logger.info("【入库的表名=" + tableName + " ,短信集合大小=" + lists.get(i).size()
                                + " ,实际入库的短信条数=" + insertRecords + "】");
                    }
                    //                int insertRecords = msgService.batchInsertMsg(entry.getKey(), entry.getValue());
                }
                //解析入库成功标志  
                isPraseAndRecordSuccess = true;
  • 相关阅读:
    print格式化输出(format)
    Python list,tuple,dict,set高级变量常用方法
    K8s的kubectl常用命令
    C/C++中数组与指针的关系探究
    Java中的不可变类
    JAVA 类总结
    c++ string类find总结
    关于看板娘的事儿
    类型转换
    计算机2进制小数点表示法
  • 原文地址:https://www.cnblogs.com/wuyun-blog/p/8532092.html
Copyright © 2011-2022 走看看