Tracking thread pool in Java

This article presents an implementation of a tracking thread pool in Java.

A tracking thread pool is a usual thread pool that records the task execution statistics like total number of tasks executed, average execution time of tasks and total execution time of all tasks. The default thread pools created by Executors class in Java does not track the execution stats leaving you no option but to implement your own thread pool that does the job.

In this article, I present an implementation of a tracking thread pool that tracks the total execution time, average execution time and the total tasks executed and provides methods to query those parameters. This is quite a powerful feature to have in a thread pool.

You can go a step further and expose these thread statistics through a JMX bean that can be queried and monitored through monitoring tools whenever desired.

Here is the implementation.

TrackingThreadPool.java

 

TrackingThreadPool tester

 

Output

 


 

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Previous article

How to create a deadlock in Java

Next article

Java String to Int