The bottom line is that Contractors abstract away low-level flow control details. It's true?
Yes.
They deal with issues such as creating thread objects, maintaining a thread pool, controlling the number of threads, as well as graceful / less graceful shutdowns. Performing these steps manually is nontrivial.
EDIT
This may or may not be a performance hit ... compared to a custom implementation ideally tuned to the exact needs of your application. But there is a possibility that:
- your custom implementation will not be fully configured, and
- the difference in performance will not be significant in any case.
In addition, the Executor support classes allow you to simply configure various parameters (for example, thread pool sizes) if there is a problem that needs to be fixed. I do not see how the overhead of garbage collection will significantly affect the use of Contractors, one way or another.
As a rule, you should focus on writing applications simply and reliably (for example, using high-level concurrency support classes), and only worry about efficiency if:
- your application is too slow and
- profiling tools tell you that you have problems in a specific area.
source share