Multithreading---Other ways to stop threads, daemon threads, join methods

Source: Internet
Author: User

Third-party Stop Threads:

It turns out to be stop (), because the method has some problems, so it is replaced by the interrupt () method, its use and mechanism is

When the frozen thread is not specified to return to the running state, the freeze needs to be purged, forcing the thread to return to the running state, which allows the action tag to end the thread.

The thread class provides the interrupt () method.

Daemon Thread:

The thread object. Setdaemon (); This method means that the foreground thread (the main thread) ends and the background thread (the background running thread) ends immediately.

Join method:

Waits for the thread to terminate. That is, when the main thread is running, it reads the beginning of the threads, that is, after start () and then the join () method, then it represents the thread request to join the run, that is,

The thread wants the CPU to execute the power. , robbing the CPU of executive power. The main thread at this time is in a frozen state, and when the thread executes, the mainline friend gets execution.

PS: When a thread executes the. Join () method to the B-thread, a waits. When the b thread is executed, a will not execute.

join can be used to temporarily join thread execution. at the same time, when the B thread has an await, the interrupt method should be used.

Multithreading---Other ways to stop threads, daemon threads, join methods

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.