|
@@ -1,13 +1,18 @@
|
|
package com.qmth.teachcloud.task.job;
|
|
package com.qmth.teachcloud.task.job;
|
|
|
|
|
|
|
|
+import com.qmth.boot.core.concurrent.service.ConcurrentService;
|
|
|
|
+import com.qmth.teachcloud.mark.enums.LockType;
|
|
import com.qmth.teachcloud.task.job.service.JobService;
|
|
import com.qmth.teachcloud.task.job.service.JobService;
|
|
import org.quartz.DisallowConcurrentExecution;
|
|
import org.quartz.DisallowConcurrentExecution;
|
|
import org.quartz.JobExecutionContext;
|
|
import org.quartz.JobExecutionContext;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.scheduling.quartz.QuartzJobBean;
|
|
import org.springframework.scheduling.quartz.QuartzJobBean;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @Description: pdf自动生成任务
|
|
* @Description: pdf自动生成任务
|
|
@@ -16,20 +21,29 @@ import javax.annotation.Resource;
|
|
* @Author: wangliang
|
|
* @Author: wangliang
|
|
* @Date: 2025/2/27
|
|
* @Date: 2025/2/27
|
|
*/
|
|
*/
|
|
-@DisallowConcurrentExecution//串行执行
|
|
|
|
|
|
+//@DisallowConcurrentExecution//串行执行
|
|
public class CreatePdfTaskJob extends QuartzJobBean {
|
|
public class CreatePdfTaskJob extends QuartzJobBean {
|
|
private final static Logger log = LoggerFactory.getLogger(CreatePdfTaskJob.class);
|
|
private final static Logger log = LoggerFactory.getLogger(CreatePdfTaskJob.class);
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
JobService jobService;
|
|
JobService jobService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private ConcurrentService concurrentService;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
protected void executeInternal(JobExecutionContext jobExecutionContext) {
|
|
protected void executeInternal(JobExecutionContext jobExecutionContext) {
|
|
- try {
|
|
|
|
- jobService.createPdfTask();
|
|
|
|
|
|
+ if (concurrentService.getReadWriteLock(LockType.CREATE_PDF.name()).writeLock().tryLock()) {
|
|
|
|
+ try {
|
|
|
|
+ jobService.createPdfTask();
|
|
// jobExecutionContext.setResult("最后执行时间:" + DateUtil.format(new Date(), SystemConstant.DEFAULT_DATE_PATTERN));
|
|
// jobExecutionContext.setResult("最后执行时间:" + DateUtil.format(new Date(), SystemConstant.DEFAULT_DATE_PATTERN));
|
|
- } catch (InterruptedException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+ concurrentService.getReadWriteLock(LockType.CREATE_PDF.name()).writeLock().unlock();
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ log.info("create-pdf-task is running");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|