[concurrency-interest] Finalization changes to DelegatedExecutorService

Doug Lea dl at cs.oswego.edu
Thu Mar 23 11:46:02 EST 2006


Jason Mehrens wrote:
> The changes for BugID 6399443 makes the DelegatedExecutorService invoke 
> shutdown when the finalizer is run.  I think there is a potential 
> problem where a live reference to a configurable executor service is 
> maintained but the unconfigurable "view" is subject to garbage 
> collection.  In the test case bellow, as soon as any one of the 
> unconfigurable views is garbage collected the live ExecutorService is 
> shutdown.
> 
> I'm not sure if this is a real world problem because it the test case 
> bellow it could just as easily return the same unconfigurable view and 
> avoid the issue.
> 

Wow, thanks for the very quick scrutiny! (This change was just barely entered.)
We (JSR166 folks) have been discussing this change for a while.
If anyone else is interested, the issue is that some users
of Executors seem to believe that they should be garbage collectable when no
longer referenced even when not shutdown. This is not always a sensible
belief, but we want to help out by making more common cases automatically
finalizable, to avoid inadvertent leaks. The change here did so harmlessly for
Executors.newSingleThreadedExecutor, but as a potential compatibility
bug byproduct, also did so for any other executor wrapped within a
unconfigurableExecutorService. We'll have to change this, because it is
just barely conceivable that someone out there could be relying on this
undocumented detail. And we've sworn not to introduce any such
incompatibilities.

(The broader moral is that even when you purposely do not specify some
behaviors, people come to rely on them, so it becomes harder and harder to
change anything at all as a set of APIs become established.)

-Doug







More information about the Concurrency-interest mailing list