How does thread’s stop method work? Stop() method of thread stops the thread execution.
The security manager, if present, checks if the current thread is trying to stop some other thread. The stop method to stop the thread is an unsafe option. Stopping a thread causes it to unlock all the monitors it has locked. It causes the damaged objects to be read by some other threads. These objects are damaged because they are left in an inconsistent state on stopping the thread.
It is always better to write a code which will modify 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.
How does thread’s stop method work? The threads stop method has been deprecated. It causes a sudden termination of a Thread's run method. If the tasks performed by the run method are critical, then the stop method could leave the program in an inconsistent state.
The stop method throws a ThreadDeath object at the thread to kill it due to which the thread dies asynchronously.