rev:定时任务线程修复

This commit is contained in:
ludj
2024-01-16 19:53:57 +08:00
parent 1e7de370dc
commit 0cea3574a8
3 changed files with 21 additions and 9 deletions

View File

@@ -28,6 +28,7 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@Api(hidden = true)
@SpringBootApplication(exclude = {
QuartzAutoConfiguration.class,
org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class
})
@ServletComponentScan //https://blog.csdn.net/qq_36850813/article/details/101194250

View File

@@ -2,18 +2,22 @@ package org.nl.system.service.quartz.utils;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.yomahub.tlog.task.quartz.TLogQuartzJobBean;
import lombok.extern.slf4j.Slf4j;
import org.nl.config.thread.ThreadPoolExecutorUtil;
import org.nl.common.utils.RedisUtils;
import org.nl.common.utils.ThrowableUtil;
import org.nl.config.SpringContextHolder;
import org.nl.config.thread.ThreadPoolExecutorUtil;
import org.nl.system.service.quartz.ISysQuartzJobService;
import org.nl.system.service.quartz.dao.SysQuartzJob;
import org.nl.system.service.quartz.dao.SysQuartzLog;
import org.nl.system.service.quartz.dao.mapper.SysQuartzLogMapper;
import org.nl.system.service.quartz.impl.SysQuartzJobServiceImpl;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.quartz.QuartzJobBean;
@@ -28,14 +32,19 @@ import java.util.concurrent.ThreadPoolExecutor;
@Async
@SuppressWarnings({"unchecked", "all"})
@Slf4j
public class ExecutionJob extends QuartzJobBean {
@DisallowConcurrentExecution
public class ExecutionJob extends TLogQuartzJobBean {
/**
* 该处仅供参考
*/
private final static ThreadPoolExecutor EXECUTOR = ThreadPoolExecutorUtil.getPoll();
@Autowired
@Qualifier("threadPoolExecutor")
private ThreadPoolExecutor EXECUTOR;
@Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
public void executeTask(JobExecutionContext context) throws JobExecutionException {
SysQuartzJob quartzJob = (SysQuartzJob) context.getMergedJobDataMap().get(SysQuartzJob.JOB_KEY);
// 获取spring bean
ISysQuartzJobService quartzJobService = SpringContextHolder.getBean(SysQuartzJobServiceImpl.class);
@@ -45,7 +54,7 @@ public class ExecutionJob extends QuartzJobBean {
String uuid = quartzJob.getUuid();
SysQuartzLog logDto = new SysQuartzLog();
logDto.setLog_id(IdUtil.getSnowflake(1,1).nextIdStr());
logDto.setLog_id(IdUtil.getSnowflake(1, 1).nextIdStr());
logDto.setJob_name(quartzJob.getJob_name());
logDto.setBean_name(quartzJob.getBean_name());
logDto.setMethod_name(quartzJob.getMethod_name());