Browse Source

fix: 定时任务无法启动

master
李永德 1 year ago
parent
commit
4db3a16a36
  1. 24
      nladmin-system/nlsso-server/src/main/java/org/nl/config/thread/ThreadPoolExecutorUtil.java

24
nladmin-system/nlsso-server/src/main/java/org/nl/config/thread/ThreadPoolExecutorUtil.java

@ -16,7 +16,11 @@
package org.nl.config.thread; package org.nl.config.thread;
import org.nl.config.SpringContextHolder; import org.dromara.dynamictp.core.support.DynamicTp;
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 +31,22 @@ 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
@DynamicTp("el-thread")
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()
); );
} }

Loading…
Cancel
Save