overridden done method not working

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

overridden done method not working

Christopher Kin Chung Au

 I made a post earlier where I said the future task cancel method was
   not working and was suggested to override the done method. I have
   since used a test program to understand the mechanics behind cancel
   and done and it all seems to work and indeed it does seem to be the
   case where when I run the cancel method the done method does get
   called.
   I have tried to apply the test concepts to the real development and
   find this to be an issue. The  idea of what I am trying to do is to
   have a parent futuretask which creates multiple child futures. When I
   overrode the the done method on the parent futuretask and called
   cancel the done method does not get called immediate even though the
   iscancelled method and isdone method both return true. The overridden
   done method only gets called when all the child futures have finished
   executing. Is there somthing I am doing wrong???
   Any help will be appreciated thanks,
   Chris


_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: overridden done method not working

Doug Lea
Christopher Kin Chung Au wrote:
>  The  idea of what I am trying to do is to
>    have a parent futuretask which creates multiple child futures. When I
>    overrode the the done method on the parent futuretask and called
>    cancel the done method does not get called immediate even though the
>    iscancelled method and isdone method both return true. The overridden
>    done method only gets called when all the child futures have finished
>    executing. Is there somthing I am doing wrong???
>

The done method fires only when the task's run/call method returns,
not upon calling cancel. Apparently your parent tasks are written not
to return until child tasks complete.

If you require that cancelling a parent task should also cancel child
tasks, then you can override FutureTask.cancel (or make your own
custom Future implementation) to do this.

Also, your tasks should all make sure to be responsive to interrupts, perhaps by
interspersing "if (Thread.interrupted()) return..."  as needed.

-Doug

_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest