Thread stop, daemon thread, join () method

Source: Internet
Author: User
Tags thread stop

One, the thread stops:
There is a stop () method, which, while still available, is obsolete, and therefore recommends the following methods.
1, stop a thread: we generally will be controlled by a variable.

2, if you need to stop a thread in the waiting state, then we need to use the variable with the Notify method or interrupt ().
Prerequisite: A thread that is in a waiting (blocking) state may keep the program running.

1) Notify (): Occasionally can stop.

2) Interrupt (): The thread's waiting state is forced to clear, the purged state of the thread will receive a Interruptedexception exception.

Second, the Guardian thread

1, daemon thread (background thread): If only a daemon thread is left in a process, then the daemon will die.

2, note: A thread default is not a daemon thread.

3, demand: Analog QQ download update package.

Three, join () method Detailed:
1, join (): Join.

2. Demand:

3, the solution:

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.