为许多用户选择和删除许多行(大约24000)时,SQL Server超时

时间:2018-10-23 03:46:47

标签: java sql-server

当我在带有SQL Server的Java中运行以下代码时,出现超时异常。它适合1个用户,但是当我同时测试多个并发用户(仅10个)时,会出现超时错误。请帮忙。

public void deleteAgmtWrkldDetail(Integer agreementId, Integer groupId, List<String> months, Integer staffId, String tempId, int userId,  String agmtNo, String staffCatCode,
        List<BigDecimal> workLoadList, AgmtWorkloadSummary wSummary) {

    Integer manSchId = insertOrUpdateManningSchedule(agreementId, groupId, staffId, tempId, userId, agmtNo);
    if(months != null && months.size() > 0) {           
        List<AgmtWorkloadDetail> existsWorkloadDetailList = workloadDao.getAllAgmtWorkloadDetailByScheduleIdAndMonthsAndCategory(manSchId, months, staffId, staffCatCode);
        existsWorkloadDetailList.forEach(x -> {
            workloadDao.remove(x);
            });
        }
    for (int k = 0; k < months.size() && k < workLoadList.size(); k++) {
        AgmtWorkloadDetail wlDetail = new AgmtWorkloadDetail();
        BigDecimal workload = BigDecimal.ZERO;
        try {
            workload = ((BigDecimal) workLoadList.get(k));
        } catch (Exception e) {
        }

        wlDetail.setSummaryId(wSummary.getSummaryId());
        wlDetail.setWorkloadDate(new Integer(months.get(k)));
        wlDetail.setWorkloadUnit(WorkloadUnit.WEEK.getValue());
        wlDetail.setWorkload((workload != null ? workload : new BigDecimal(0)));
        wlDetail.setStaffCatCode(staffCatCode);
        wlDetail.setCreateDate(LocalDateTime.now());
        wlDetail.setCreateUser(userId);
        wlDetail.setUpdateDate(LocalDateTime.now());
        wlDetail.setUpdateUser(userId);
        workloadDao.persist(wlDetail);
        }
    }

下面是insertOrUpdateManningSchedule()的代码

public Integer insertOrUpdateManningSchedule (Integer agreementId, Integer groupId, Integer staffId, String tempId, int userId, String agmtNo) {
    AgmtManSch manningSchedule = manningScheduleDao.getAllAgreementManningScheduleByAgmtIdAndGroupId(agreementId, groupId);

    final LocalDateTime now = LocalDateTime.now();
    if (manningSchedule != null) {
    manningSchedule.setSubmitDate(LocalDateTime.now());
    manningSchedule.setHibVersion(manningSchedule.getHibVersion()+1);
    manningSchedule.setUpdateDate(now);
    manningSchedule.setUpdateUser(userId);  
    workloadDao.merge(manningSchedule);
    } else {
        // create a new manning schedule as there is no recored with the given project Id
        AgmtManSch agmtManSch = new AgmtManSch();
        agmtManSch.setGroupId(groupId);
        agmtManSch.setAgmtId(agreementId);
        agmtManSch.setAgmtNo(agmtNo);   
        agmtManSch.setYear(now.getYear());
        agmtManSch.setPeriod(now.getMonthValue());              
        agmtManSch.setSubmitDate(now);      
        agmtManSch.setCreateDate(now);
        agmtManSch.setCreateUser(userId);
        agmtManSch.setUpdateDate(now);
        agmtManSch.setUpdateUser(userId);   
        workloadDao.persist(agmtManSch);
    }
    return manningSchedule.getScheduleId();
}

以下是我得到的例外情况

网络-2018-10-23 11:40:30,608 [http-nio-8080-exec-1]警告o.h.e.jdbc.spi.SqlExceptionHelper-SQL错误:0,SQLState:null 网路-2018-10-23 11:40:30,609 [http-nio-8080-exec-1]错误o.h.e.jdbc.spi.SqlExceptionHelper-连接已关闭。 互联网-2018-10-23 11:40:30,645 [http-nio-8080-exec-1]错误o.s.t.i.TransactionInterceptor-应用程序异常被回滚异常覆盖 javax.persistence.PersistenceException:org.hibernate.exception.GenericJDBCException:无法准备语句     在org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:147)     在org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:155)     在org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1419)     在org.hibernate.Query.getResultList(Query.java:427)     在hk.gov.devb.pwcrar.dao.ManningScheduleDao.getAllAgreementManningScheduleByAgmtIdAndGroupId(ManningScheduleDao.java:545)     在hk.gov.devb.pwcrar.service.impl.AgreementServiceImpl.insertOrUpdateManningSchedule(AgreementServiceImpl.java:1404)     在hk.gov.devb.pwcrar.service.impl.AgreementServiceImpl.deleteAgmtWrkldDetail(AgreementServiceImpl.java:1373)

提前谢谢!

0 个答案:

没有答案