Java thread: thread stack model and java thread model

Source: Internet
Author: User

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.

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.