Spring框架监视ThreadPoolTask​​Executor队列大小

时间:2016-10-18 18:42:43

标签: spring jmx spring-jmx jmxtrans

我查看了http://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutor.html

队列大小没有getter,只有队列容量。

如果我使用jmx监视ThreadPoolTask​​Executor,我如何监视队列大小级别以确保它健康?

1 个答案:

答案 0 :(得分:7)

executor.getThreadPoolExecutor().getQueue().size()

修改

@ManagedResource
public class MyTEMBean {

    private final ThreadPoolTaskExecutor te;

    public MyTEMBean(ThreadPoolTaskExecutor te) {
        this.te = te;
    }

    @ManagedAttribute
    public int getQueueSize() {
        this.te.getThreadPoolExecutor().getQueue().size();
    }

}