Please enable JavaScript.
Coggle requires JavaScript to display documents.
8.4 Extending ThreadPoolExecutor - Coggle Diagram
8.4 Extending ThreadPoolExecutor
Purpose
Designed for extension
Offers hook methods for customizing behavior:
beforeExecute
afterExecute
terminated
beforeExecute
Called before task execution
Runs in task-executing thread
Use cases:
Logging
Monitoring
Timing
Statistics gathering
If it throws a RuntimeException:
Task is not executed
afterExecute is not called
afterExecute
Called after task execution
Runs in task-executing thread
Triggered by:
Normal completion
Exception thrown
Not called if task ends with an Error
Use cases:
Logging
Measuring task duration
Gathering result data
terminated
Called after shutdown completes
All tasks and worker threads have terminated
Use cases:
Releasing executor lifecycle resources
Final logging
Sending shutdown notifications
Final statistics/report generation