思路:
    数据切割。分批次,批量插入。每次批量插入1000条数据。如果万级数据,循环插入10次就完成了。根据实际情况调整。————如果数据量是十万级,百万级以上,可以考虑多线程、并行流快速处理。

    1. private final static int SIZE = 1000;
    2. public static void main(String[] args) throws Exception {
    3. List<InfoDto> feeList = new ArrayList<>();
    4. for (int i = 0; i < 10000; i++) {
    5. InfoDto infoDto = new InfoDto();
    6. infoDto.setName("name" + i);
    7. infoDto.setBirthday("birthday" + i);
    8. infoDto.setAge("" + i);
    9. infoDto.setSex("" + i);
    10. feeList.add(infoDto);
    11. }
    12. insertBigData.insertData(feeList);
    13. }
    14. public static void insertData(List list) {
    15. if (list == null || list.size() < 1) {
    16. return;
    17. }
    18. List<List> streamList = new ArrayList<>();
    19. for (int i = 0; i < list.size(); i += SIZE) {
    20. int j = Math.min((i + SIZE), list.size());
    21. List subList = list.subList(i, j);
    22. streamList.add(subList);
    23. }
    24. System.out.println("分割:");
    25. for (List list1:streamList) {
    26. insertFrozenBuckleList(list1);
    27. }
    28. }
    29. public static Consumer<List> insertFrozenBuckleList(List<InfoDto> sourceList) {
    30. Consumer<List> consumer = (List x) -> {
    31. List<InfoDto> infoDtoList = (List<InfoDto>) x;
    32. System.out.println("批量导入插入----"+x.get(0));
    33. };
    34. consumer.accept(sourceList);
    35. return consumer;
    36. }