To understand the principle of thread scheduling and the thread execution process, you must understand the line stacks model.
Line stacks refers to the stack information of the memory thread dispatching at a certain time, the method that is currently called is always at the top of the stack. The content of the line stacks is dynamically changing as the program runs, so the research thread stack must choose a running moment (actually where the code is running).
Next, let's say the process of stacks with this code and picture
Package cn.happy.bdqn; Public classtestrunnable {/** * @param args*/ Public Static voidMain (string[] args) {//TODO auto-generated Method StubSystem. out. println ("Hello world!"); Newtestrunnable (); } Public voidMeThod () {dosomething DS1=NewDoSomething ("three o"); Thread T1=NewThread (DS1); T1.start (); }}
As you can see, when the code executes to two moments (1 and 2), the virtual machine calls the stack process.
When the program executes to T1.start (), it can be seen that the program has one more branch, (add a call stack B), so stack A and stack B are executed in parallel.
Java Threading: Line stacks Model