I've switched from ThreadPoolExecutor
to ThreadPoolTaskExecutor
in my Spring Boot project just because according to it's documentation:
This class is well suited for management and monitoring (e.g. through JMX)
I've created a bean of ThreadPoolTaskExecutor
in my configuration class like this:
@Bean
ThreadPoolTaskExecutor profileTaskExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setThreadGroupName(getClass().getSimpleName());
taskExecutor.setCorePoolSize(corePoolSize);
taskExecutor.setMaxPoolSize(maxPoolSize);
taskExecutor.setKeepAliveSeconds(KEEP_ALIVE_MINUTES);
taskExecutor.setQueueCapacity(1);
taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
return taskExecutor;
}
@Bean
protected MBeanExporter mbeanExporter() {
MBeanExporter exporter = new MBeanExporter();
Map<String, Object> beans = new HashMap<>();
beans.put("org.springframework.boot:type=Executors,name=ProfileServiceExecutor", profileTaskExecutor());
exporter.setBeans(beans);
return exporter;
}
This runs fine and exposes my ThreadPoolTaskExecutor
via JMX. Now the problem is since I'm creating a new MBeanExporter my other ManagedOperations gets overridden and don't show up in JConsole. Now my question is:
- Is there a way to add
ThreadPoolTaskExecutor
to exisisting managed beans. I've tried but could not succeed. - Is this the most efficient way to do this? Isn't there any annotation that I can put on above bean?
@ManagedOperation
does not work on method level.