[concurrency-interest]Re: comments on Executor

Mark D. Anderson mda@discerning.com
Sat, 2 Feb 2002 19:53:57 -0800

> Using the "stronger" interruptible version of Runnable task from my
> last mail, 
> The Executor-object doesn't know anything about
> these things except to replace dead worker threads with fresh ones.

In the lines of your sample code:
  public synchronized void cancel() {
    if (!isDone()) return;
that "!" shouldn't be there, right?

Also, how does the Executor know not to interrupt the thread if the cancel() has done so?
Does it check isCancelled() or isInterrupted() first?
If the Executor is one of the ones that runs things in its own thread, wouldn't
it be anti-social for cancel() to kill itself (and take out the Executor too)?

> > > So you can use any number of CompositeTasks with the same executor,
> > > and cancel each composite independently. Is there something else you
> > > need?
> > 
> > Well, for example, I need a way to wait up to msecs on just the tasks in the CompositeTask.
> You can use a java.util.Timer task to send out a
> CompositeTask.cancelAll at the timeout period. (It is harmless if the
> cancel goes out even though they are all finished, and probably
> cheaper to leave it this way rather than cancelling the cancellation.)

Unless i'm missing something, that isn't sufficient because it provides no synchronization.
What i want is something that says "wait at most msecs for everything to be done; if they
all finish sooner, return as soon as that is true; if some are not done at msecs, then
cancel/interrupt them and return".

Even better would be if CompositeTask had methods like:
   int getNumberDoneOk();
   int getNumberDoneException();
   int getNumberCancelled(); // cancel() called before they were started
   int getNumberTimeout(); // started but not done by the timeout
Those being the 4 possible final states I can imagine.

It would be ok if those above functions can only be called after I have called my desired:
  void waitAll(long msecs); // wait at most msecs for all to be done; kill the ones not done by then