Chapter 10. Threading
Note
In this chapter:
From its earliest days, Java has been a multithreaded environment. While the threading capabilities are formidable in Java 1.4, Tiger introduces a whole new slew of concurrency utilities, allowing for further tweaking of your multithreaded programs.
Handling Uncaught Exceptions in Threads
Normally a Java thread (represented by any class that extends java.lang.Thread) stops
when its run( ) method completes. In an abnormal
case, such as when something goes wrong, the thread can terminate by
throwing an exception. This exception trickles up the thread’s
ThreadGroup hierarchy, and if it gets to the root ThreadGroup, the default behavior is to print out the thread’s name, exception name, exception
message, and exception stack trace.
To get around this behavior (at least in Java 1.4 and earlier), you’ve got
to insert your own code into the ThreadGroup hierarchy, handle the
exception, and prevent delegation back to the root ThreadGroup. While
this is certainly possible, you’ll have to define your own subclass of
ThreadGroup, make sure any Threads you create are assigned to that group, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access