Saturday, 15 July 2017

As stop() method is deprecated, How can we terminate or stop infinitely running thread in java?

Infinitely running thread can be stopped using interrupt() method.


Let’s understand Why stop() method is deprecated :
Stopping a thread with Thread.stop() causes it to release all of the monitors that it has locked. If any of the objects previously protected by these monitors were in an inconsistent state, the damaged objects become visible to other threads, which might lead to unpredictable behavior.

No comments:

Post a Comment