123456789101112131415161718192021222324252627282930313233343536 |
- package cn.com.qmth.am.task;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.scheduling.annotation.Scheduled;
- import org.springframework.stereotype.Service;
- import com.qmth.boot.core.concurrent.service.ConcurrentService;
- import cn.com.qmth.am.enums.LockType;
- import cn.com.qmth.am.service.QuestionService;
- @Service
- public class QuestionImportJob {
- @Autowired
- private ConcurrentService concurrentService;
- @Autowired
- private QuestionService questionService;
- @Scheduled(fixedDelay = 5 * 1000, initialDelay = 5 * 1000)
- public void doJob() {
- boolean lock = concurrentService.getReadWriteLock(LockType.QUESTION_IMPORT.name()).writeLock().tryLock();
- try {
- if (!lock) {
- return;
- }
- questionService.importQuestion();
- } finally {
- if (lock) {
- concurrentService.getReadWriteLock(LockType.QUESTION_IMPORT.name()).writeLock().unlock();
- }
- }
- }
- }
|