Spring framework monitoring ThreadPoolTaskExecutor queue size
Asked Answered
S

1

10

I checked http://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutor.html

There is no getter for queue size, only queue capacity.

If I use jmx to monnitor ThreadPoolTaskExecutor, how can I monitor queue size level to make sure it is healthy?

Samson answered 18/10, 2016 at 18:42 Comment(0)
C
15

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

EDIT

@ManagedResource
public class MyTEMBean {

    private final ThreadPoolTaskExecutor te;

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

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

}
Ceruse answered 18/10, 2016 at 19:47 Comment(4)
In this case, if I want to simply use jmxtrans-agent github.com/jmxtrans/jmxtrans-agent to query application, should I have my own executor extend this class and add getter for queue size. Does this sounds the right way?Samson
Or a simple MBean wrapper exposing the properties you want - it doesn't have to be a subclass.Ceruse
forgive my lack of knowledge, I thought jmx need to have getter for the attributes to be expose. If ThreadPoolTaskExecutor don't have such getter, and if I don't subclass to implement it. How Jmx can query this attributes? Curious what does it means by MBean wrapper. Great thanksSamson
Just wrap the TE in a class and expose that as an MBean instead of the TE itself. See the edit to my answer.Ceruse

© 2022 - 2024 — McMap. All rights reserved.