Java interrupt mechanism is a cooperative mechanism, which means that another thread cannot be directly terminated through interruption, and the interrupted thread needs to handle the interruption by itself. This is like parents at home telling their children to take care of their health, but whether and how their children take care of their health is entirely up to them.
Java threads also have a way to prevent the run method from completing, and that is the stop method. However, this method has been deprecated by jdk. Why? If your thread is modifying data somewhere, be it a database or writing a file, and the stop method kills the thread without any explanation, will the data be chaotic or inconsistent? Therefore, Java threads use an interrupt mechanism, and you can capture this interrupt and perform the operations required after the interruption.
Detailed analysis of Java interrupt mechanism
Java threads also have a way to prevent the run method from completing, and that is the stop method. However, this method has been deprecated by jdk. Why? If your thread is modifying data somewhere, be it a database or writing a file, and the stop method kills the thread without any explanation, will the data be chaotic or inconsistent? Therefore, Java threads use an interrupt mechanism, and you can capture this interrupt and perform the operations required after the interruption.