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?

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
edi
  • 223
  • 5
  • 12

1 Answers1

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();
    }

}
samblake
  • 1,517
  • 3
  • 16
  • 33
Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • In this case, if I want to simply use jmxtrans-agent https://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? – edi Oct 18 '16 at 21:05
  • Or a simple MBean wrapper exposing the properties you want - it doesn't have to be a subclass. – Gary Russell Oct 18 '16 at 21:31
  • 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 thanks – edi Oct 20 '16 at 19:33
  • Just wrap the TE in a class and expose __that__ as an MBean instead of the TE itself. See the edit to my answer. – Gary Russell Oct 20 '16 at 19:48