As in previous chapters, we will finish up with a discussion of obvious caveats. This section discusses things to be aware of when working with threads and synchronization in Java.
The single most dangerous part of the Java thread API, are the methods in the java.lang.Thread
class called stop
, resume
, and suspend
. They were included in Java 1.0, but immediately found unsafe and deprecated. This however, was a bit too late, and, even today, they are widely used both in legacy code and new applications, despite the deprecation warnings. We are sad to report that we've come across them in commercial code that was developed as late as 2008.
The stop
method (meant to halt the execution of a thread) is unsafe. This is because stopping the execution of a thread that is modifying global data would possibly leave the global data in an inconsistent, broken state. A thread that receives a stop signal will unlock all of the...