Implementing a thread pool inside a Service

后端 未结 2 874
春和景丽
春和景丽 2021-02-13 21:31

I\'m currently working on implementing a Service that when requested will perform some work on several parallel threads.

My implementation is based on the <

2条回答
  •  不要未来只要你来
    2021-02-13 21:55

    1. No. shutdownNow attempts to interrupt the currently actively tasks. There are no guarantees that it will able to do it
    2. Yes it is. From the documentation:

      Once neither of these situations hold, the service's onDestroy() method is called and the service is effectively terminated. All cleanup (stopping threads, unregistering receivers) should be complete upon returning from onDestroy().

    3. there is no reason to have those members declared as static. static member are associated withe class rather than with any object, and the common use is to share the same static member between different (services in your case) instances.
    4. You should read carefully the documentation about all the possible implementations of the BlockingQueue interface, but I doubt that, for normal cases use, you will see differences from the performances perspective.

提交回复
热议问题