I’m firing up
Executors.newFixedThreadPool(100);
in a main program and the producer is pumping in jobs faster than the consumers can keep up. Is there a way to see how many items are queued up in the underlying unbounded queue that the newFixedThreadPool uses?
Use
java.util.concurrent.ThreadPoolExecutor#getTaskCountto get the number of the scheduled tasks in the thread pool. However, note that this is just an approximation and may not be exact.If you want to solve the issue of the producer producing tasks faster than the consumer, limit the size of the underlying queue and pass in one of the implementations of
RejectedExecutionHandlerwhen creating thejava.util.concurrent.ThreadPoolExecutor. See the snippet below from the doc ofThreadPoolExecutor: