What are the benefits of Java – executors?
In a life without Java executors, a new thread must be created for each runnable task Creating new threads requires thread overhead (creation and disassembly), which increases complexity and wastes the time of non executor programs
Reference code:
No Java executor –
new Thread (aRunnableObject).start ();
Using java executor –
Executor executor = some Executor factory method; exector.execute (aRunnable);
The bottom line is that executors abstract the low - level details of how to manage threads
Really?
thank you.
Solution
Yes
They deal with issues such as creating thread objects, maintaining thread pools, controlling the number of running threads, and graceful / less normal shutdown It is not easy to do these things by hand
edit
This may or may not have a performance impact... Compared to a custom implementation that is completely tailored to the precise needs of the application But the opportunities are:
>Your custom implementation won't adjust perfectly, and > performance won't vary much anyway
In addition, if there are problems to be solved, the executor support class allows you to simply adjust various parameters (such as thread pool size) I don't see the use of executors. Either way, the garbage collection overhead will be seriously affected
As a general rule, you should focus on writing applications simply and robustly (for example, using advanced concurrency support classes) and worry about performance only in the following cases:
>Your application is "too slow" and the > analysis tool tells you that you are experiencing problems in a specific area