Thread.stop

Thread.stop

Class Overview | Class Members | This Package | All Packages

Syntax 1
public final void stop()
Description
Forces the thread to stop executing.

First, the checkAccess method of this thread is called with no arguments. 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.

Exceptions
SecurityException if the current thread cannot modify this thread.
See Also
checkAccess, run, start, ThreadDeath, uncaughtException



Syntax 2
public final synchronized void stop( Throwable o )
Parameters
obj
the Throwable object to be thrown.
Description
Forces the thread to stop executing.

First, the checkAccess method of this thread is called with no arguments. This may result in throwing a SecurityException (in the current thread).

If the argument obj is null, a NullPointerException is thrown (in the current thread).

The thread represented by this thread is forced to complete whatever it is doing abnormally and to throw the Throwable object obj as an exception. This is an unusual action to take; normally, the stop method that takes no arguments should be used.

It is permitted to stop a thread that has not yet been started. If the thread is eventually started, it immediately terminates.

Exceptions
SecurityException if the current thread cannot modify this thread.
See Also
checkAccess, run, start, stop