Reacting on cancellation events

Hi

I need to to catch any cancellation event to roll back an ArrayBlockingQueue in case the process does not run through all the way and can return the Object to the ArrayBlockingQueue normally.

What is the best way to do this?

Felix

You need to call ExecutionContext.checkCanceled regularly (you need to do it anyway, otherwise cancelation does not work [1]). Catch the exception that is potentially thrown out of this method and do your bookeeping. Make sure to rethrow the CanceledExecutionException afterwards.

[1] The thread is also interrupted which may cause an InterruptedException if you node is waiting in some system call (e.g. I/O).

Thanks for the reply. Your answer resembles others that were already given in this forum. Sorry for troubling you, but somehow, I could, at the time, not quite believe that this will fit to my particular case. Seems to work though...

Cheers