java - Why doesn't all `Executors` factory methods wrap in a `FinalizableDelegatedExecutorService`? -
executors#newsinglethreadexecutor()
returns threadpoolexecutor
wrapped in finalizabledelegatedexecutorservice
(not public). finalizabledelegatedexecutorservice
makes sure thread pool shut down when garbage collected.
why aren't executorservice
s returned executors
wrapped in finalizabledelegatedexecutorservice
? threadpoolexecutor
shut down without being wrapped in finalizabledelegatedexecutorservice
if garbage collected?
first of all, shouldn't relying on finalization in first place. 1 argue none of them should wrapped.
anyway, not pools created executors
factory methods same. of core pool size of zero, there no threads clean up.
similarly forkjoinpool cleans idle threads after 2 seconds , becomes gcable once there no threads keep alive, there's no need explicit finalization.
Comments
Post a Comment