- Config file
package org.blog.test;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.jmx.export.MBeanExporter;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.HashMap;
import java.util.Map;
@SpringBootApplication
@Slf4j
public class JmxApplication {
public static void main(String[] args) {
SpringApplication.run(JmxApplication.class, args);
}
@Bean
public ThreadPoolTaskExecutor threadPoolTaskExecutor() {
return new ThreadPoolTaskExecutor() {{
setCorePoolSize(2);
setMaxPoolSize(5);
setQueueCapacity(10);
initialize();
}};
}
@Bean
public MBeanExporter myMbeanExporter() {
return new MBeanExporter() {{
Map beans = new HashMap<>();
beans.put("org.blog.test:name=threadPoolTaskExecutor", threadPoolTaskExecutor().getThreadPoolExecutor());
setBeans(beans);
}};
}
}
You can declare the bean as MBeanExporter, and then register threadPoolTaskExecutor as one of beans.
By using jconsole in JAVA_HOME/bin/jconsole, you can monitor your jvm application.
You can find the declared Mbean in Mbean tab.
댓글 없음 :
댓글 쓰기