java-Preliminary Understanding-14th chapter-Multithreading (Guardian line Setdaemon)

Source: Internet
Author: User

One.

In addition to the interrupt method, there are other ways

We want to introduce some common methods in threading class, such as Setdaemon,

Or a combination of the previous examples to explain, T1 and T2 Two threads, we interrupt one, the other is not interrupted, then the DOS result will not end.

However, if it is set as a daemon thread before T2 is turned on, the Guardian cannot understand it and can think of it as a background thread. Previously known threads are foreground threads,

The DOS results are shown as ended.

What is the difference between the two? Background thread is characterized in that it and the foreground thread are normally open, that is, the end is not the same, run all the same, the execution of the CPU to rob each other, the end of the time, the foreground thread must be a manual end, such as set the form of the mark to end it, you do not end it will always wait, in this resource Waiting for the CPU to process it. And for the background thread is called, if all the foreground thread is finished, the background thread regardless of state, all automatically end, the background seems to have a dependency on the foreground, you in I also in, you run I also run, you disappear I also disappear. The foreground thread is not, this disappears, this is still there.

Does that help? Let's just give you a quick example. You are responsible for the input, I am responsible for the output, you do not input, I will not output, you are finished, I still need to exist? I can set it up as a background.

This is what the background thread says. If you want a thread to do a basic attachment, when it ends depending on other threads, it can be defined as a background,

java-Preliminary Understanding-14th chapter-Multithreading (Guardian line Setdaemon)

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.