Java thread: thread stack model and java thread model
To understand the Thread Scheduling Principle and the thread execution process, you must understand the thread stack model.
The thread stack refers to the stack information of Thread Scheduling in the memory at a certain time point. The method currently called is always at the top of the stack. The content of the thread stack changes dynamically with the running of the program. Therefore, to study the thread stack, You must select a runtime (actually, where the code runs ).
Next, we will explain the thread stack process based on this code and image.
Package cn. happy. bdqn; public class TestRunnable {/*** @ param args */public static void main (String [] args) {// TODO Auto-generated method stub System. out. println ("Hello World! "); New TestRunnable ();} public void meThod () {DoSomething ds1 = new DoSomething (" A 3 "); Thread t1 = new Thread (ds1 ); t1.start ();}}
It can be seen that when the code is executed at two times (1 and 2), the virtual machine calls the stack process.
When the program runs to t1.start (), it can be seen that the program has an additional branch (A call stack B is added), so that stack A and stack B are executed in parallel.