In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the states of Java threads". The content of the explanation in this article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought. Let's study and learn "what are the states of Java threads"?
Java thread state transition diagram
Java thread status
In the life cycle of Java threads, according to complex concurrency scenarios, the states of Java threads can be divided into seven types, namely: new, runnable, runnable, indefinite waiting, indefinite waiting, blocking, ending.
1. New (New) status
A new thread object is created and has not been executed yet.
two。 Runnable (Runnable or Ready) statu
The newly created thread is in the Runnable state after calling the start method, and the thread that has just finished waiting (acquiring the lock) or blocking state is also in the Runnable state, and the thread in this state is in the runnable thread pool, waiting to acquire CPU resources.
3. Operational (Running) status
Threads in Runnable state get CPU resources and execute program code.
4. Indefinite wait (Waiting) status
The locked object in the synchronized code block calls its wait () method or calls the join () method of another thread in the current thread, then the current thread will release the occupied lock, release CPU resources, block in the waiting queue, and wait for the object modified by synchronized to call the notify () or notifyAll () method to wake up or join's other thread execution ends (abnormal exit). In concurrency, after the thread waiting indefinitely is awakened, it has to compete for the lock of the object. If there is no competition, the thread will be blocked in the lock pool of the object, and after the competition to the lock, the thread will be in Runnable state.
5. Deadline wait (Timed Waiting) status
Unlike the indefinite wait (Waiting) state, the wait limit is passed in when the wait and join methods are called. In addition, when a thread calls the sleep () method, it is in a Timed Waiting state, which releases CPU resources, but does not release the lock until it becomes Runnable after hibernation.
6. Blocking (Blocked) state
When a threaded program executes to the synchronized code block or the Reentrant.lock () method, when the object's lock is occupied by other threads, the current thread will be blocked in the object's lock pool and be in a Blocked state.
7. End (Terminated) status
When a thread's run method completes execution or exits abnormally, the thread's life cycle ends and cannot be used again.
Thank you for reading, the above is the content of "what are the states of Java threads?" after the study of this article, I believe you have a deeper understanding of the status of Java threads, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.