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;
  • 相关阅读:
    比赛F-F Perpetuum Mobile
    HDU 1003(A
    C-C Radar Installation 解题报告
    Codeforces 18C C. Stripe
    HDU 4911 Inversion
    分蛋糕(C
    抄书(B
    深入了解Android蓝牙Bluetooth——《基础篇》
    2W 字详解 Redis 集群环境搭建实践
    漫画 | 阿姨,我不想努力了~
  • 原文地址:https://www.cnblogs.com/wuyun-blog/p/8532092.html
Copyright © 2011-2022 走看看