Java Thread life cycle

Source: Internet
Author: User
When I was doing my big project in junior high, the main interface couldn't come out when my server opened the thread that listened to the client's request. I believe we all know that there is a process preemption that happens. But I was depressed, obviously I opened a sub-thread, why and the main thread occurred preemption? After studying, I found my thread to start the function with the Thread.run (). When I changed run to Thread.Start (), the problem was solved. At this point, let's take a look at the threading mechanism of this thing.

As shown, the thread is divided into 5 states.   New, ready, running, dead, blocked. NEW: The process has just been newly created, new ready: The thread can run. The start () function runs on the surface thread, but it is not yet running.   When in a blocking state, the blocking condition resolves to a functioning state. Run: the thread runs.   The only way into the run is to call the function run (). Blocking: The thread is stopped for some reason and needs to be resolved for some reason to run. Resolves the post to Ready state.  The Sleep (), Yieid (), join () method can be called to stop or pause. Death: The thread dies automatically when the run () method has finished executing. To let a thread die, do not use Stop (), it is best not to let while () loop, break out, let the Run method executes, the thread died normally.    Or, call interrupt when the thread state is in a blocked state. This blog writes quite detailed http://blog.csdn.net/lonelyroamer/article/details/7949969 my problem, because I use Run (), let the thread start to execute, The Accept () method waits for the client to connect. and start () is to let it into the waiting state, when the interface is displayed and then executed. It won't make the main interface go out.

Java Thread life cycle

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.