/**
* Forces the thread to stop executing.
*
* If there is a security manager installed, its checkAccess
* method is called with this
* as its argument. This may result in a
* SecurityException
being raised (in the current thread).
*
* If this thread is different from the current thread (that is, the current
* thread is trying to stop a thread other than itself), the
* security manager's checkPermission
method (with a
* RuntimePermission("stopThread")
argument) is called in
* addition.
* Again, this may result in throwing a
* SecurityException
(in the current thread).
*
* The thread represented by this thread is forced to stop whatever
* it is doing abnormally and to throw a newly created
* ThreadDeath
object as an exception.
*
* It is permitted to stop a thread that has not yet been started.
* If the thread is eventually started, it immediately terminates.
*
* An application should not normally try to catch
* ThreadDeath
unless it must do some extraordinary
* cleanup operation (note that the throwing of
* ThreadDeath
causes finally
clauses of
* try
statements to be executed before the thread
* officially dies). If a catch
clause catches a
* ThreadDeath
object, it is important to rethrow the
* object so that the thread actually dies.
*
* The top-level error handler that reacts to otherwise uncaught
* exceptions does not print out a message or otherwise notify the
* application if the uncaught exception is an instance of
* ThreadDeath
.
*
* @exception SecurityException if the current thread cannot
* modify this thread.
* @see #interrupt()
* @see #checkAccess()
* @see #run()
* @see #start()
* @see ThreadDeath
* @see ThreadGroup#uncaughtException(Thread,Throwable)
* @see SecurityManager#checkAccess(Thread)
* @see SecurityManager#checkPermission
* @deprecated This method is inherently unsafe. Stopping a thread with
* Thread.stop causes it to unlock all of the monitors that it
* has locked (as a natural consequence of the unchecked
* ThreadDeath
exception propagating up the stack). If
* any of the objects previously protected by these monitors were in
* an inconsistent state, the damaged objects become visible to
* other threads, potentially resulting in arbitrary behavior. Many
* uses of stop
should be replaced by code that simply
* modifies some variable to indicate that the target thread should
* stop running. The target thread should check this variable
* regularly, and return from its run method in an orderly fashion
* if the variable indicates that it is to stop running. If the
* target thread waits for long periods (on a condition variable,
* for example), the interrupt
method should be used to
* interrupt the wait.
* For more information, see
* Why
* are Thread.stop, Thread.suspend and Thread.resume Deprecated?.
*/
@Deprecated
public final void stop() {
SecurityManager security = System.getSecurityManager();
if (security != null) {
checkAccess();
if (this != Thread.currentThread()) {
security.checkPermission(SecurityConstants.STOP_THREAD_PERMISSION);
}
}
// A zero status value corresponds to "NEW", it can't change to
// not-NEW because we hold the lock.
if (threadStatus != 0) {
resume(); // Wake up thread if it was suspended; no-op otherwise
}
// The VM can handle all thread states
stop0(new ThreadDeath());
}