Skip to main content


Showing posts from May, 2018

Java Tips: Creating a Monitoring-friendly ExecutorService

In this article we will be extending an ExecutorService implementation with monitoring capabilities. This monitoring capability will help us to measure a number of pool parameters i.e., active threads, work queue size etc. in a live production environment. It will also enable us to measure task execution time, successful tasks count, and failed tasks count. Monitoring Library As for the monitoring library we will be using Metrics . For the sake of simplicity we will be using a ConsoleReporter which will report our metrics to the console. For production-grade applications, we should use an advanced reporter (i.e., Graphite reporter). If you are unfamiliar with Metrics, then I recommend you to go through the getting started guide . Let's get started. Extending the ThreadPoolExecutor We will be using  ThreadPoolExecutor as the base class for our new type. Let's call it  MonitoredThreadPoolExecutor . This class will accept a MetricRegistry as one of its construct