I'm currently looking for a nasty bug in a multi-threaded environment using FutureTasks and Executors. The basic idea is to have a fixed number of threads execute separate FutureTasks that calculate the result that should be displayed in the table (not paying attention to the GUI aspect here).
I've been looking at this for so long, I'm starting to doubt my sanity.
Consider this piece of code:
public class MyTask extends FutureTask<Result> {
private String cellId;
...
protected void done() {
if (isCancelled()) return;
try {
Result r = get();
...
sendMessage(cellId, r);
} catch (ExecutionException e) {
...
} catch (InterruptedException e) {
...
}
}
...
}
When done()Executor is called that processes the MyTask instance, I check to see if I got there because the task was canceled. If so, I skip all other steps, especially I do not name sendMessage().
The documentation for FutureTask.done () says:
, , isDone ( ). . , . , , , . ( API)
, FutureTask, done(). , isCancelled() , - cancel()? isCancelled() == true ?
, , ? isDone(), , , isCancelled() , , .
, , .