You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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);
}
}