[concurrency-interest] ScheduledThreadPoolExecutor lost exception?

Doug Lea dl at cs.oswego.edu
Tue May 24 16:38:07 EDT 2005

TAlison at ameritrade.com wrote:
> I'm extending ScheduledThreadPoolExecutor to implement the afterExecute
> method so that I can log any runtime exceptions thrown by scheduled
> tasks. However, I've found that runtime exceptions do not actually make
> it to afterExecute. It appears the Sync used by the FutureTask that
> wraps the scheduled task catches the exception and calls setException
> but does not rethrow it. Thus, the runTask method of
> ThreadPoolExecutor$Worker never passes it to to afterExecute. 

A periodic task is not considered to have completed until
it is cancelled -- its run() method is repeatedly called until then.
So, afterExecute is only called after the final re-running.

The spec is not the least bit clear about this though.
Sorry, and thanks for reporting it!

Additionally, it would be equally sensible to do this
the way you expected it to work.

We'll discuss whether we should clarify or change the spec and/or
the code.


More information about the Concurrency-interest mailing list