What is so great about artists?

In a life without Java executives, new threads must be created for every Runnable task. Creating new threads requires threading overhead (creation and shutdown), which add complexity and waste time for a program other than Executor.

Referring to the code:

no java executor -

new Thread (aRunnableObject).start (); 

with Java executor -

 Executor executor = some Executor factory method; exector.execute (aRunnable); 

The bottom line is that artists abstractly describe low-level information about how to manage threads.

It's true?

Thanks.

+4
source share
3 answers

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.
+10
source

A couple of advantages of performers versus regular streams.

  • Throttling can be easily achieved by resizing ThreadPools. This helps to control / check the number of threads flowing through your application. Especially useful when benchmarking your application for load.
  • Better runnable task management can be achieved with RejectionHandlers.
+1
source

I think all that performers do is that they will perform low-level tasks for you, but you still need to intelligently decide which thread pool you want. I mean, if your use case requires a maximum of 5 threads, and you go and use a thread pool that has 100 threads, then of course it is going to affect performance. In addition, there is additional emphasis being placed on the low level that will stop the system. And the last of all, it is always better to understand what is being done at a low level so that it gives us a fair idea of โ€‹โ€‹underground things.

0
source

All Articles