zoukankan      html  css  js  c++  java
  • list集合多线程分批导入Mysql

    public int addFreshStudentsNew(List<FreshStudentAndStudentModel> list, String schoolNo) {
        if (list == null || list.isEmpty()) {
            return 0;
        }
        List<StudentEntity> studentEntityList = new LinkedList<>();
        List<EnrollStudentEntity> enrollStudentEntityList = new LinkedList<>();
        List<AllusersEntity> allusersEntityList = new LinkedList<>();

        list.forEach(freshStudentAndStudentModel -> {
            EnrollStudentEntity enrollStudentEntity = new EnrollStudentEntity();
            StudentEntity studentEntity = new StudentEntity();
            BeanUtils.copyProperties(freshStudentAndStudentModel, studentEntity);
            BeanUtils.copyProperties(freshStudentAndStudentModel, enrollStudentEntity);
            String operator = TenancyContext.UserID.get();
            String studentId = BaseUuidUtils.base58Uuid();
            enrollStudentEntity.setId(BaseUuidUtils.base58Uuid());
            enrollStudentEntity.setStudentId(studentId);
            enrollStudentEntity.setIdentityCardId(freshStudentAndStudentModel.getIdCard());
            enrollStudentEntity.setOperator(operator);
            studentEntity.setId(studentId);
            studentEntity.setIdentityCardId(freshStudentAndStudentModel.getIdCard());
            studentEntity.setOperator(operator);
            studentEntityList.add(studentEntity);
            enrollStudentEntityList.add(enrollStudentEntity);
        
            AllusersEntity allusersEntity = new AllusersEntity();
            allusersEntity.setId(enrollStudentEntity.getId());
            allusersEntity.setUserCode(enrollStudentEntity.getNemtCode());
            allusersEntity.setUserName(enrollStudentEntity.getName());
            allusersEntity.setSchoolNo(schoolNo);
            allusersEntity.setTelNum(enrollStudentEntity.getTelNum());
            allusersEntity.setPassword(enrollStudentEntity.getNemtCode());  //密码设置为考生号
            allusersEntityList.add(allusersEntity);
        });


        int nThreads = 50;
        
        int size = enrollStudentEntityList.size();
        ExecutorService executorService = Executors.newFixedThreadPool(nThreads);
        List<Future<Integer>> futures = new ArrayList<Future<Integer>>(nThreads);
        
        for (int i = 0; i < nThreads; i++) {
            final List<EnrollStudentEntity> EnrollStudentEntityImputList = enrollStudentEntityList.subList(size / nThreads * i, size / nThreads * (i + 1));
            final List<StudentEntity> studentEntityImportList = studentEntityList.subList(size / nThreads * i, size / nThreads * (i + 1));
            final List<AllusersEntity> allusersEntityImportList = allusersEntityList.subList(size / nThreads * i, size / nThreads * (i + 1));
        
           Callable<Integer> task1 = () -> {
          studentSave.saveStudent(EnrollStudentEntityImputList,studentEntityImportList,allusersEntityImportList);
               return 1;
            };
          futures.add(executorService.submit(task1));
        }
        executorService.shutdown();
        if (!futures.isEmpty() && futures != null) {
            return 10;
        }
        return -10;
    }

    看完打开支付宝扫一扫领个红包吧!


  • 相关阅读:
    www.insidesql.org
    kevinekline----------------- SQLSERVER MVP
    Sys.dm_os_wait_stats Sys.dm_performance_counters
    如何使用 DBCC MEMORYSTATUS 命令来监视 SQL Server 2005 中的内存使用情况
    VITAM POST MORTEM – ANALYZING DEADLOCKED SCHEDULERS MINI DUMP FROM SQL SERVER
    Cargo, Rust’s Package Manager
    建筑识图入门(初学者 入门)
    Tracing SQL Queries in Real Time for MySQL Databases using WinDbg and Basic Assembler Knowledge
    Microsoft SQL Server R Services
    The Rambling DBA: Jonathan Kehayias
  • 原文地址:https://www.cnblogs.com/shihaiming/p/15538499.html
Copyright © 2011-2022 走看看