opt:定时下发任务优化

This commit is contained in:
DESKTOP-5DIJMF9\admin
2025-08-07 10:20:14 +08:00
parent d999a4a33c
commit 94c9baf2a6
2 changed files with 20 additions and 21 deletions

View File

@@ -16,7 +16,10 @@
package org.nl.config.thread;
import org.nl.config.SpringContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
@@ -27,16 +30,21 @@ import java.util.concurrent.TimeUnit;
* @author Zheng Jie
* @date 2019年10月31日18:16:47
*/
@Configuration
public class ThreadPoolExecutorUtil {
public static ThreadPoolExecutor getPoll(){
AsyncTaskProperties properties = SpringContextHolder.getBean(AsyncTaskProperties.class);
@Autowired
private AsyncTaskProperties asyncTaskProperties;
@Bean
@Primary
public ThreadPoolExecutor threadPoolExecutor() {
return new ThreadPoolExecutor(
properties.getCorePoolSize(),
properties.getMaxPoolSize(),
properties.getKeepAliveSeconds(),
asyncTaskProperties.getCorePoolSize(),
asyncTaskProperties.getMaxPoolSize(),
asyncTaskProperties.getKeepAliveSeconds(),
TimeUnit.SECONDS,
new ArrayBlockingQueue<>(properties.getQueueCapacity()),
new ArrayBlockingQueue<>(asyncTaskProperties.getQueueCapacity()),
new TheadFactoryName()
);
}

View File

@@ -11,13 +11,11 @@ import org.nl.wms.sch_manage.enums.TaskStatus;
import org.nl.wms.sch_manage.service.ISchBaseTaskService;
import org.nl.wms.sch_manage.service.dao.SchBaseTask;
import org.nl.wms.warehouse_manage.enums.IOSConstant;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.concurrent.TimeUnit;
@Slf4j
@Component
@@ -40,17 +38,9 @@ public class AutoTask {
//定时任务
@SneakyThrows
public void run() {
RLock lock = redissonClient.getLock(this.getClass().getName());
boolean tryLock = lock.tryLock(0, TimeUnit.SECONDS);
try {
if (tryLock) {
sendTask();
}
} catch (Exception e) {
if (tryLock) {
lock.unlock();
}
}
log.info("定时器正在执行下发任务调度...");
sendTask();
log.info("定时器执行下发任务调度结束...");
}
/**
@@ -60,7 +50,8 @@ public class AutoTask {
System.out.println("定时下发任务开始--------------------------"+ DateUtil.now());
List<SchBaseTask> taskList = taskService.list(new LambdaQueryWrapper<SchBaseTask>()
.eq(SchBaseTask::getIs_delete, IOSConstant.IS_DELETE_NO)
.eq(SchBaseTask::getTask_status, TaskStatus.CREATE.getCode()));
.eq(SchBaseTask::getTask_status, TaskStatus.CREATE.getCode())
.orderByAsc(SchBaseTask::getTask_group_seq));
if (ObjectUtil.isEmpty(taskList)) {
return;
}