Home > Java > JavaBase > Java zero-based detailed explanation of multi-threading

Java zero-based detailed explanation of multi-threading

coldplay.xixi
Release: 2021-03-04 10:20:39
forward
1723 people have browsed it

Java zero-based detailed explanation of multi-threading

Daemon thread

Thread classification can be divided into: User thread (above They are all about user threads), and the other is daemon thread. The daemon thread is like this. When all user threads end their life cycle, the daemon thread will end its life cycle. As long as there is one user thread, the daemon thread will not end. For example, the famous Garbage Collector## in Java #It is a daemon thread. It will not end until all threads in the application end.

(Free learning recommendation:

java basic tutorial)

User thread

As can be seen from the above, the main thread execution has ended, but the user thread still prints the data

Modify it to a daemon (service thread) thread

##After setting it as a daemon thread, When the main thread ends, the daemon thread does not end after outputting all the data. In other words, the daemon thread serves

user threads.

When all user threads end, the daemon thread will Automatically endTimer Timer

##The above program will be output at 2010-02-20 15:23:10, and output once every 24 hours

[Code example], use anonymous classes to implement the above Function

The above program will output at 2010-02-20 15:29:10, once every 2 seconds. There are special third-party open source products about the schedule, such as :

Quartz

window

##Timer Focus on mastering

The concepts of processes and threads

  1. Threads Two implementation methods

  2. Thread,RunnableUnderstand the priority of the thread

  3. The meaning of sleep

  4. If you end a thread correctly

  5. The meaning of thread synchronization (synchronous sharing There is no sharing of resources and local variables)

  6. The concept of daemon thread

  7. Understand Timer

  8. Understand the plans provided by winodw

The above is the detailed content of Java zero-based detailed explanation of multi-threading. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template