Using the Synchronized keyword to modify the synchronization method;
Against the use of Stop () is because it is unsafe. It unlocks all locks acquired by the thread, and
And if the object is in an incoherent state, then other threads can check and modify it in that State
Children The result is difficult to check out the real problem;
The suspend () method is prone to deadlocks. When calling suspend (), the target line routines to stop,
But still hold the lock that was acquired before that. At this point, no other thread can access the locked resource.
Unless the thread that is "suspended" resumes running. For any thread to say, if they want to restore the target thread,
Attempting to use any of the locked resources at the same time will cause a deadlock. Therefore, suspend () should not be used,
Instead, place a flag in your thread class that indicates whether the thread should be active or suspended. If the logo
Indicates that the thread should hang, and wait () is used to enter the wait state. If the flag indicates that the thread should be restored,
The thread is restarted with a notify ().
Why is the Stop () and Suspend () methods in Java threads not recommended?