opt:定时下发任务优化
This commit is contained in:
@@ -16,7 +16,10 @@
|
|||||||
package org.nl.config.thread;
|
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.ArrayBlockingQueue;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
@@ -27,16 +30,21 @@ import java.util.concurrent.TimeUnit;
|
|||||||
* @author Zheng Jie
|
* @author Zheng Jie
|
||||||
* @date 2019年10月31日18:16:47
|
* @date 2019年10月31日18:16:47
|
||||||
*/
|
*/
|
||||||
|
@Configuration
|
||||||
public class ThreadPoolExecutorUtil {
|
public class ThreadPoolExecutorUtil {
|
||||||
|
|
||||||
public static ThreadPoolExecutor getPoll(){
|
@Autowired
|
||||||
AsyncTaskProperties properties = SpringContextHolder.getBean(AsyncTaskProperties.class);
|
private AsyncTaskProperties asyncTaskProperties;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@Primary
|
||||||
|
public ThreadPoolExecutor threadPoolExecutor() {
|
||||||
return new ThreadPoolExecutor(
|
return new ThreadPoolExecutor(
|
||||||
properties.getCorePoolSize(),
|
asyncTaskProperties.getCorePoolSize(),
|
||||||
properties.getMaxPoolSize(),
|
asyncTaskProperties.getMaxPoolSize(),
|
||||||
properties.getKeepAliveSeconds(),
|
asyncTaskProperties.getKeepAliveSeconds(),
|
||||||
TimeUnit.SECONDS,
|
TimeUnit.SECONDS,
|
||||||
new ArrayBlockingQueue<>(properties.getQueueCapacity()),
|
new ArrayBlockingQueue<>(asyncTaskProperties.getQueueCapacity()),
|
||||||
new TheadFactoryName()
|
new TheadFactoryName()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.ISchBaseTaskService;
|
||||||
import org.nl.wms.sch_manage.service.dao.SchBaseTask;
|
import org.nl.wms.sch_manage.service.dao.SchBaseTask;
|
||||||
import org.nl.wms.warehouse_manage.enums.IOSConstant;
|
import org.nl.wms.warehouse_manage.enums.IOSConstant;
|
||||||
import org.redisson.api.RLock;
|
|
||||||
import org.redisson.api.RedissonClient;
|
import org.redisson.api.RedissonClient;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
@@ -40,17 +38,9 @@ public class AutoTask {
|
|||||||
//定时任务
|
//定时任务
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public void run() {
|
public void run() {
|
||||||
RLock lock = redissonClient.getLock(this.getClass().getName());
|
log.info("定时器正在执行下发任务调度...");
|
||||||
boolean tryLock = lock.tryLock(0, TimeUnit.SECONDS);
|
sendTask();
|
||||||
try {
|
log.info("定时器执行下发任务调度结束...");
|
||||||
if (tryLock) {
|
|
||||||
sendTask();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
if (tryLock) {
|
|
||||||
lock.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,7 +50,8 @@ public class AutoTask {
|
|||||||
System.out.println("定时下发任务开始--------------------------"+ DateUtil.now());
|
System.out.println("定时下发任务开始--------------------------"+ DateUtil.now());
|
||||||
List<SchBaseTask> taskList = taskService.list(new LambdaQueryWrapper<SchBaseTask>()
|
List<SchBaseTask> taskList = taskService.list(new LambdaQueryWrapper<SchBaseTask>()
|
||||||
.eq(SchBaseTask::getIs_delete, IOSConstant.IS_DELETE_NO)
|
.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)) {
|
if (ObjectUtil.isEmpty(taskList)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user