[concurrency-interest]RE: comments on Executor

David Holmes dholmes@dltech.com.au
Mon, 4 Feb 2002 09:43:39 +1000


> Mark D. Anderson wrote:
> Also, neither FutureResult nor Callable have a cancel() function
> that would be used when the Executor shuts it down before it is ready.
> If the result finishes on its own (even with its own exception
> other than InterruptedException), then cleanup is its own duty. But if
> someone is going to shoot it  in the head, it'd be nice if they'd call
> the cancel() function first.

It is not clear to me what the issue is here. My understanding is that
executors execute tasks to completion before commencing with the next task.
This means that a "task group" that was cancelled would consist, at worst,
of a set of completed tasks, a set of unstarted tasks and a current task
that could be at any point in its execution. There is obviously no cleanup
issue with regard to the completed or unstarted tasks.

The task that is in the midst of execution can not be "shot in the head" -
this is Java - all you can do is ask something to "shoot itself". A
cancellation request will become evident to a task via an exception -
typically InterruptedException - and that exception should lead to abrupt
termination of the task and ultimately the executor thread will lets itself
die. This means that clean-up is purely within the control of the task
itself, simply by catching the exception before allowing it to propogate -
just as if it had been its own exception.

David Holmes