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

Java zero-based detailed explanation of multi-threading

coldplay.xixi
coldplay.xixi forward
2021-03-04 10:20:39 1596browse

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 isdaemon 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 famousGarbage 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

##TimerFocus 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!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete