[concurrency-interest] throwing RuntimeException vs ExceptioninThreadPoolExecutor

David Holmes davidcholmes at aapt.net.au
Sun May 30 18:03:48 EDT 2010

Kai Meder writes:
> On 30.05.2010 01:57, David Holmes wrote:
> > Re-reading this ...
> >
> >> Kai Meder writes:
> >>> I'm hacking in Scala and use the ThreadPoolExecutor. I use an
> >>> Exception "TerminatedChannel", using the trait ControlThrowable,
> >>> inside my tasks in for ControlFlow (please no discussion about this).
> >>>
> >>> When using TerminatedChannel as a RuntimeException it passes the
> >>> attached ThreadPoolExector-CodeBlock. If used just as a Throwable the
> >>> ThreadPoolExecutor suspends the thread, as TerminatedChannel
> >>> broke its neck.
> >
> > So Throwable is a checked-exception and it should not be possible (under
> > normal circumstances) for your task to throw it as Runnables do
> > not throw checked exceptions. You can get around this by using some
> > techniques or native code to throw "impossible" exceptions. If
> > you did this there may some internal piece of code that encounters a
> > that results in the behaviour you observe.
> If declaring the TerminatedChannel as RuntimeException with
> ControlThrowable it is an Unchecked Exception and seems to leave the
> ThreadPoolExecutor, caught by the "proper" exception-handler outside the
> task. The ThreadPoolExecutor's Task#X-Thread does not get "suspended",
> the control flow continues normally.

As said previously, exceptions thrown by the executor thread can't be caught
by the thread submitting the task - unless code has been set up explicitly
to do this. Perhaps this is specific to the Scala runtime?

> > That said I don't understand what you mean by "suspends the
> > thread" above.
> The ThreadPoolExecutor Task#X-Thread encounters the NON-RuntimeException
> and enters the JVM-"Suspended" ThreadState, as indicated by the
> Debug-View of eclipse.

That sounds like the debugger has "suspended" the thread - possibly because
of the unexpected uncaught checked exception. What happens if you run
outside of the debugger/IDE ?

David Holmes

More information about the Concurrency-interest mailing list