Вот один из способов ...
@ManagedResource
public class MyExecutor extends ThreadPoolTaskExecutor {
private static final long serialVersionUID = 1L;
@ManagedAttribute
@Override
public int getCorePoolSize() {
return super.getCorePoolSize();
}
@ManagedAttribute
@Override
public int getMaxPoolSize() {
return super.getMaxPoolSize();
}
@ManagedAttribute
@Override
public int getKeepAliveSeconds() {
return super.getKeepAliveSeconds();
}
@ManagedAttribute
@Override
public int getPoolSize() {
return super.getPoolSize();
}
@ManagedAttribute
@Override
public int getActiveCount() {
return super.getActiveCount();
}
}
и
@Bean
MyExecutor exec() {
MyExecutor taskExecutor = new MyExecutor();
taskExecutor.setThreadGroupName(getClass().getSimpleName());
taskExecutor.setCorePoolSize(10);
taskExecutor.setMaxPoolSize(20);
taskExecutor.setKeepAliveSeconds(5);
taskExecutor.setQueueCapacity(1);
taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
return taskExecutor;
}
Он будет получен экспортером ботинка.
EDIT
Или просто переопределить автоматически настроенный экспортер загрузки по умолчанию ...
@Bean
@Primary
public AnnotationMBeanExporter mbeanExporter(ObjectNamingStrategy namingStrategy,
Environment environment, BeanFactory beanFactory) {
AnnotationMBeanExporter exporter = new AnnotationMBeanExporter();
exporter.setRegistrationPolicy(RegistrationPolicy.FAIL_ON_EXISTING);
exporter.setNamingStrategy(namingStrategy);
String serverBean = environment.getProperty("spring.jmx.server",
"mbeanServer");
if (StringUtils.hasLength(serverBean)) {
exporter.setServer(beanFactory.getBean(serverBean, MBeanServer.class));
}
Map<String, Object> beans = new HashMap<>();
beans.put("org.springframework.boot:type=Executors,name=ProfileServiceExecutor", profileTaskExecutor());
exporter.setBeans(beans);
return exporter;
}