ThreadPoolExecutor and finalization
peter.levart at gmail.com
Tue Oct 31 08:25:25 UTC 2017
On 10/31/17 08:45, David Holmes wrote:
>>> The docs for TPE cover this in detail: 
>>> A pool that is no longer referenced in a program AND has no
>>> remaining threads will be shutdown automatically. If you would like
>>> to ensure that unreferenced pools are reclaimed even if users forget
>>> to call shutdown(), then you must arrange that unused threads
>>> eventually die, by setting appropriate keep-alive times, using a
>>> lower bound of zero core threads and/or setting
>> I'm trying to understand the purpose of finalize() in TPE, but can't.
>> I'm surely missing something. If the pool is no longer referenced AND
>> there are no active threads, what is there left to shutdown()
>> actually? All that remains is garbage that will eventually be GCed.
> Ummmmm .... I'm going to have to do some archaeology here ...
I can imagine a thread pool where worker threads, while idling, don't
have a reference to the pool so the pool can shutdown() itself when:
- the pool is no longer referenced AND
- there is no worker thread executing a task (i.e. all worker threads
In such state, the pool is not reachable and may be shutdown.
But it seems that TPE is not such a pool.
>> Regards, Peter
More information about the core-libs-dev