简体   繁体   中英

How long can I leave a threadpool without tasks before it terminates in android?

I am new to using ThreadPools to perform multithreading in my android app. In the past, I have created new Threads to perform network requests, database queries and intense algorithms. Acording to this post new Thread(task).start() VS ThreadPoolExecutor.submit(task) in Android , Using a thread pool is better.

As I was redesigning my program to use a ThreadpoolExecutor, The question that I have been struggling to answer is "What happens to my threadPool if no tasks are sent to it for a while?" For example, say that I am building an app that pulls information from a server and displays it to a user. The user can also update the displayed information by pulling an updated set of data from the server. The user can update the information at any time they please. It could be as long as several hours between updates.

This could be accomplished using a new Threads, however, each time the end user refreshes, new memory must be allocated for the thread. What I am hoping to do is use a threadPool so that I can run the network calls without having to allocate memory every time. However that is built on two assumptions. The first is that I can leave a threadpool alone for an undeterminable amount of time and still be able to use it. The second is that this aproach to using a thread model is in line with good practice. Assuming the second is true, How long can I leave a threadpool without tasks to perform before it shuts down or terminates on its own accord, if it does do that?

我相信,除非您在线程池上显式调用“ shutdown()”,否则它在应用程序的生命周期内仍然可用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM