Why Java threads do not recommend calling the Stop,suspend,resume method

Source: Internet
Author: User

First, stop

The Stop method is not recommended, and the official word is "an unpredictable problem may occur." In fact, the thread stops itself after calling the Stop method. When the thread stops, it stops executing and frees the lock resource that it is using. The problem here is that if a thread takes a lock, takes only a few steps, and has a few steps left to execute, if the lock is released at this time, the other thread takes over again, which can cause the thread to be unsafe. And the problem is almost impossible to debug.

Ii. Suspend and Resume methods

These two methods must appear in pairs, otherwise it is very easy to deadlock because the Suspend method does not release the lock. If there is no guarantee that someone will call the Resume method later, it will cause the thread to hang forever. Second, the suspend and resume methods are usually not necessarily a thread in order to execute. It is possible that one thread suspend another thread to resume, and if it does not handle the order of calls between threads, it is very likely that the resume occurs before suspend, which in turn causes the thread to suspend, and no one will ever resume him, "thread freezes "The scene.

Why Java threads do not recommend calling the Stop,suspend,resume method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.