For Java developers, multithreading should be a knowledge point that must be skilled in application, especially for developing Java-based products. This article will give an in-depth explanation of the knowledge points of Java multithreading. In the subsequent series, it will focus on the design idea, implementation and application of concurrent parallel packages provided by Professor Doug Lea in Java 5.
How can we get it deeper? My understanding is that there is a problem, not a general view. Therefore, this series mainly focuses on solving problems. Of course, I also hope that readers can come up with better solutions and more questions. Due to the limited level, if there are any errors, please raise them and discuss them together. In short, I hope that through this series we will have a deep understanding of Java multithreading to solve our actual development problems.
As a developer, I don't think it is necessary to discuss the basic knowledge of multithreading, such as what is a thread? How to create and so on, these knowledge points can be obtained through books and Google. This series focuses on how to deeply understand multithreading to help our normal development, such as how to implement the thread pool? How to Apply locks.
(1) What is the use of join? Simple answer: How to synchronize synchronization? How to implement it? The answer is as follows.
Since I started to use Java multithreading, I have never understood join. JDK says this:
Join
Public final voidJoin(Long millis) throws
Interruptedexception
Waits at mostMillis
Milliseconds for this thread to die. A timeout
0
Means to wait forever.
Do you understand this? It literally means waiting for a while until this thread dies. My question is whether the thread is its own thread or the thread that calls it. The code above: