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)