Monitoring an Executor framework
The Executor
framework provides a mechanism that separates the implementation of tasks from thread creation and management to execute the tasks. If you use an executor, you only have to implement Runnable
objects and send them to the executor. It is the responsibility of an executor to manage threads. When you send a task to an executor, it tries to use a pooled thread for executing the task in order to avoid the creation of new threads. This mechanism is offered by the Executor
interface and its implementing classes as the ThreadPoolExecutor
class.
In this recipe, you will learn what information you can obtain about the status of a ThreadPoolExecutor
executor and how to obtain it.
Getting ready
The example of this recipe has been implemented using the Eclipse IDE. If you use Eclipse or a different IDE, such as NetBeans, open it and create a new Java project.
How to do it...
Follow these steps to implement the example:
- Create a class named
Task
that implements...