34 lines
857 B
34 lines
857 B
package com.yeguang.common.thread;
|
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.noear.solon.annotation.Bean;
|
|
import org.noear.solon.annotation.Configuration;
|
|
import org.noear.solon.annotation.Inject;
|
|
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
|
|
@Slf4j
|
|
@Configuration
|
|
@RequiredArgsConstructor
|
|
public class ThreadExecutorConfig {
|
|
|
|
private final ThreadPoolConfig threadPoolConfig;
|
|
|
|
|
|
// @Primary
|
|
@Bean(name = "customThreadPool")
|
|
public ThreadPoolExecutor getCustomExecutor(@Inject("${thread.enabled}") boolean enabled) {
|
|
if (enabled) {
|
|
return generateExecutor(threadPoolConfig);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private ThreadPoolExecutor generateExecutor(ThreadPoolConfig threadPoolConfig) {
|
|
return new MonitorThreadPoolExecutor(threadPoolConfig);
|
|
}
|
|
|
|
|
|
}
|
|
|