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