The basic concepts of threads, the basic state of threads, and the relationship between states

Source: Internet
Author: User

A program can have multiple threads executing simultaneously, a thread is an execution thread in the program, each thread is associated with the code to be executed, that can have more than one program code to run concurrently,

Each program has at least one thread, which is the thread that the main method executes. If it's just a CPU, how can it execute multiple programs at the same time? This is from a macro point of view, the CPU will execute a clue,

A will execute B Clue, switch time quickly, give a person's feeling is a, b at the same time execution, like everyone in the same office Internet, only a link to the external network cable, in fact, this cable will be a transmission of data,

One will pass data for B, because the switching time is very short, so, everyone feels at the same time the Internet.

Status: Ready, running, synchronize blocking, wait and sleep hangs, end. Wait must be called inside Synchroniz ed. The thread enters the ready state after invoking the start method of the thread.

The thread dispatch system turns the thread of the ready state into the running state, and when it encounters the synchronized statement, it becomes blocked by the running state, and when the synchronized gets the lock, the block shifts to run.

In this case, you can call the wait method to the pending state, and when the thread-associated code finishes executing, the thread becomes the end state.

The basic concepts of threads, the basic state of threads, and the relationship between states

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.