Tuesday, March 17, 2009

Java - threads have no return codes


Java threads do not return exit codes. This is a problem as a thread gets its own stack and exceptions from the thread cannot be caught by the parent thread, as it has its own stack. Exceptions are placed in the thread stack, and as a result only the thread throwing the exceptions can catch them.

The Concurrent interface allows us to get a return code from a thread with the introduction of a new abstraction - The Task. Here, a Task accepts a Callable interface that provides for an exit code.