|
@@ -11,6 +11,7 @@ import com.qmth.exam.reserve.enums.EventType;
|
|
import com.qmth.exam.reserve.service.OperateLogService;
|
|
import com.qmth.exam.reserve.service.OperateLogService;
|
|
import com.qmth.exam.reserve.service.StudentApplyService;
|
|
import com.qmth.exam.reserve.service.StudentApplyService;
|
|
import com.qmth.exam.reserve.util.JsonHelper;
|
|
import com.qmth.exam.reserve.util.JsonHelper;
|
|
|
|
+import org.redisson.api.RLock;
|
|
import org.redisson.api.RQueue;
|
|
import org.redisson.api.RQueue;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -18,8 +19,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
-import java.util.concurrent.locks.Lock;
|
|
|
|
-
|
|
|
|
@Component
|
|
@Component
|
|
public class StudentApplyRecordJob {
|
|
public class StudentApplyRecordJob {
|
|
|
|
|
|
@@ -45,8 +44,8 @@ public class StudentApplyRecordJob {
|
|
public void saveStudentApplyRecordJob() {
|
|
public void saveStudentApplyRecordJob() {
|
|
long start = System.currentTimeMillis();
|
|
long start = System.currentTimeMillis();
|
|
|
|
|
|
|
|
+ RLock curLock = (RLock) concurrentService.getLock(CacheConstants.LOCK_STUDENT_APPLY_RECORD);
|
|
try {
|
|
try {
|
|
- Lock curLock = concurrentService.getLock(CacheConstants.LOCK_STUDENT_APPLY_RECORD);
|
|
|
|
if (!curLock.tryLock()) {
|
|
if (!curLock.tryLock()) {
|
|
log.info("[JOB] locking...");
|
|
log.info("[JOB] locking...");
|
|
return;
|
|
return;
|
|
@@ -69,11 +68,18 @@ public class StudentApplyRecordJob {
|
|
log.error("[JOB] offerQueue:{} studentId:{} err:{}", success, value.getStudentId(), e.getMessage());
|
|
log.error("[JOB] offerQueue:{} studentId:{} err:{}", success, value.getStudentId(), e.getMessage());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- curLock.unlock();
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
log.error("[JOB] err:{}", e.getMessage(), e);
|
|
log.error("[JOB] err:{}", e.getMessage(), e);
|
|
} finally {
|
|
} finally {
|
|
|
|
+ try {
|
|
|
|
+ // 解锁前检查当前线程是否持有该锁
|
|
|
|
+ if (curLock.isLocked() && curLock.isHeldByCurrentThread()) {
|
|
|
|
+ curLock.unlock();
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ // ignore
|
|
|
|
+ }
|
|
|
|
+
|
|
long end = System.currentTimeMillis();
|
|
long end = System.currentTimeMillis();
|
|
log.info("[JOB] cost:{}ms", end - start);
|
|
log.info("[JOB] cost:{}ms", end - start);
|
|
}
|
|
}
|