Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring framework monitoring ThreadPoolTaskExecutor queue size

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?

like image 360
edi Avatar asked Oct 18 '16 18:10

edi


People also ask

How do I find the queue size in ThreadPoolTaskExecutor?

You can just autowire in your ThreadPoolTaskExecutor and get the queue with getThreadPoolExecutor(). getQueue() .

What is core pool size in ThreadPoolTaskExecutor?

The corePoolSize is the minimum number of workers to keep alive without timing out. It is a configurable property of ThreadPoolTaskExecutor. However, the ThreadPoolTaskExecutor abstraction delegates setting this value to the underlying java. util.

What is the use of TaskExecutor in Spring?

The TaskExecutor was originally created to give other Spring components an abstraction for thread pooling where needed. Components such as the ApplicationEventMulticaster , JMS's AbstractMessageListenerContainer , and Quartz integration all use the TaskExecutor abstraction to pool threads.


1 Answers

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

}
like image 186
Gary Russell Avatar answered Sep 20 '22 14:09

Gary Russell