Cancel a thread

The ability to end a thread externally allows you to cancel threads that run long requests before they are completed on their own. The methods available for canceling threads vary according to the threads API set that is used.

Some API sets provide well-defined points for the cancelation action to occur or other mechanisms that allow one thread to control when another thread ends. Some API sets also provide a mechanism to run cleanup code before the thread ends or to set the result of the canceled thread to a specific value.

Use thread cancelation carefully. If your API set does not provide well-defined cancelation points or a mechanism for the thread to clean up the application data and locks, you might damage data or cause deadlocks within your application.

Note: In Java™ Development Kit version 1.2 or later, the resume, stop, and suspend methods for the thread class have been deprecated. This is because these methods are considered unsafe. The functions provided by these methods can be implemented by other mechanisms, such as checking the state of some variables. See the Sun Java tutorial at http://java.sun.com/docs/books/tutorial/ Link outside information center for the recommended mechanism for a given version of Java.
Related concepts
Suspend a thread
Resume a thread