[concurrency-interest] Finalization changes to DelegatedExecutorService

Jason Mehrens jason_mehrens at hotmail.com
Thu Mar 23 11:29:13 EST 2006


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.

Regards,

Jason Mehrens


//====Test case==============
import java.util.concurrent.*;

public class TPExTest {
  private ExecutorService privatePool = Executors.newFixedThreadPool(1);

  public ExecutorService getExecutorService() {
    return Executors.unconfigurableExecutorService(privatePool);
  }

  public static void main(String[] args) {
    TPExTest test = new TPExTest();
    for(int i=Integer.MIN_VALUE; i<Integer.MAX_VALUE; i++) {
      if(test.getExecutorService().isShutdown()) {
        throw new AssertionError();
      }
      System.gc();
    }
    test.getExecutorService().shutdown();
  }
}




More information about the Concurrency-interest mailing list