I've read quite a lot about this over the last couple of hours, and I just don't see any reason ( real reason) for calling shutdown() on the ExecutorService unless we have a huge application that stores, dozens and dozens of different executor services that are not used for a long time.
The only thing (from what I understood) that happens at the end of the job is to do what the normal thread does as soon as it does. When a regular thread completes the Runnable (or Callable) method, it will be passed to the garbage collector for collection. With the help of the Executor Service, threads will simply be suspended, they will not be marked for garbage collection. This requires a shutdown.
Ok, back to my question. Is there any reason to cause the shutdown of the ExecutorService to ExecutorService very often, or even immediately after giving it any tasks? I would like to leave behind the case when someone does this, and immediately after that calls awaitTermination() as it is checked. Once we do this, we must re-create a new ExecutorService to do the same. Isn't the whole idea for an ExecutorService reusing threads? So why destroy the ExecutorService so quickly?
Isn't that a rational way to just create an ExecutorService (or a couple depending on how much you need), then pass the tasks to them as soon as they appear, and then exit when you exit the application or at some other important stages. performers?
I would like to get an answer from some experienced programmers who write a lot of asynchronous code using ExecutorServices.
The second question, a little less deals with the Android platform. If some of you say that you should not close the artists each time, and you are programming on Android, could you tell us how you deal with these shutdowns (or rather, when you execute them) when we are dealing with various life events application loop.
Due to CommonsWare comment, I made the post neutral. I'm really not interested in arguing about it to death, and it seems to lead there. I'm only interested in what I asked experienced developers if they wanted to share their experience. Thank you
java android executorservice
Lucas Apr 20 '13 at 17:09 2013-04-20 17:09
source share