Răsfoiți Sursa

切换锁服务的实现类为自定义读写锁;
还原三个后台任务触发controller,统一改为即时尝试上锁,任务完成解锁

luoshi 6 ani în urmă
părinte
comite
9a910d05ad

+ 2 - 2
stmms-biz/src/main/java/cn/com/qmth/stmms/biz/lock/LockService.java

@@ -9,7 +9,7 @@ import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationContextAware;
 import org.springframework.stereotype.Component;
 
-import cn.com.qmth.stmms.biz.lock.impl.JdkLockProvider;
+import cn.com.qmth.stmms.biz.lock.impl.CustomLockProvider;
 import cn.com.qmth.stmms.common.enums.LockType;
 
 @Component("lockService")
@@ -100,7 +100,7 @@ public class LockService implements InitializingBean, ApplicationContextAware {
 
     @Override
     public void afterPropertiesSet() throws Exception {
-        this.provider = this.context.getBean(JdkLockProvider.class);
+        this.provider = this.context.getBean(CustomLockProvider.class);
     }
 
     @Override

+ 0 - 6
stmms-biz/src/main/java/cn/com/qmth/stmms/biz/mark/thread/MarkQualityThread.java

@@ -34,12 +34,6 @@ public class MarkQualityThread implements Runnable {
     public void run() {
         LockService lockService = SpringContextHolder.getBean(LockService.class);
         MarkService markService = SpringContextHolder.getBean(MarkService.class);
-
-        if (!lockService.trylock(LockType.BATCH_QUALITY, lockKey)) {
-            log.info("mark quality thread lock faile for key=" + lockKey);
-            return;
-        }
-
         if (markers != null && markService != null) {
             for (Marker marker : markers) {
                 try {

+ 1 - 1
stmms-web/src/main/java/cn/com/qmth/stmms/admin/exam/MarkQualityController.java

@@ -95,7 +95,7 @@ public class MarkQualityController extends BaseExamController {
         MarkGroup group = groupService.findOne(examId, subjectCode, groupNumber);
         if (group != null) {
             final String lockKey = getLockKey(examId, subjectCode, groupNumber);
-            if (!lockService.isLocked(LockType.BATCH_QUALITY, lockKey)) {
+            if (lockService.trylock(LockType.BATCH_QUALITY, lockKey)) {
                 taskExecutor.submit(new MarkQualityThread(
                         markerService.findByExamAndSubjectAndGroup(examId, subjectCode, groupNumber), lockKey));
             }

+ 1 - 1
stmms-web/src/main/java/cn/com/qmth/stmms/admin/exam/ScoreController.java

@@ -196,7 +196,7 @@ public class ScoreController extends BaseExamController {
     @RoleRequire(Role.SCHOOL_ADMIN)
     public ModelAndView calculate(HttpServletRequest request) {
         int examId = getSessionExamId(request);
-        if (!lockService.isLocked(LockType.SCORE_CALCULATE, examId)) {
+        if (lockService.trylock(LockType.SCORE_CALCULATE, examId)) {
             ScoreCalculateThread thread = new ScoreCalculateThread(examId, lockService, studentService, questionService,
                     markService, reportService, examService, subjectService, groupService);
             taskExecutor.submit(thread);

+ 0 - 6
stmms-web/src/main/java/cn/com/qmth/stmms/admin/thread/ScoreCalculateThread.java

@@ -78,12 +78,6 @@ public class ScoreCalculateThread implements Runnable {
 
     @Override
     public void run() {
-        // 尝试上锁
-        if (!lockService.trylock(LockType.SCORE_CALCULATE, examId)) {
-            log.info("calculate lock faile for examId=" + examId);
-            return;
-        }
-        // 上锁成功正式开始
         log.info("start calculate for examId=" + examId);
         try {
             // 获取考试信息

+ 1 - 1
stmms-web/src/main/java/cn/com/qmth/stmms/api/controller/PictureController.java

@@ -114,7 +114,7 @@ public class PictureController {
             result.accumulate("message", "file.save not exists");
             return result;
         }
-        if (!lockService.isLocked(LockType.SAVE_SHEET, examId)) {
+        if (lockService.trylock(LockType.SAVE_SHEET, examId)) {
             taskExecutor.submit(new SheetDownloadThread(examId, saveDir, withTag, this, studentService, lockService));
         }
         result.accumulate("running", lockService.isLocked(LockType.SAVE_SHEET, examId));

+ 0 - 4
stmms-web/src/main/java/cn/com/qmth/stmms/api/utils/SheetDownloadThread.java

@@ -43,10 +43,6 @@ public class SheetDownloadThread implements Runnable {
 
     @Override
     public void run() {
-        if (!lockService.trylock(LockType.SAVE_SHEET, examId)) {
-            return;
-        }
-
         try {
             ExamStudentSearchQuery query = new ExamStudentSearchQuery();
             query.setExamId(examId);