How thread series one thread works

Source: Internet
Author: User
Tags cpu usage

1  Public Static void Main (string[] args)throws  Exception {2         new Thread (new myrunnable ("Hello1")); 3         Th.start (); 4         SYSTEM.OUT.PRINTLN ("Current main thread" +5         System.out.println ("the thread" +Th.getname ()); 6 }

The above code, in the memory state as shown. The following steps are performed primarily in the four step below.

1, run the above Java file, the virtual machine executes the class's entry main function, assigned a main thread.

2, the main method in the main thread in the stack, the stack, the instance of a new sub-thread, and opened the child thread

3. The JVM assigns a sub-line stacks to the child thread, and executes the run () stack in this sub-thread stack.

4, by the CPU scheduling each thread, allocated to each thread of time, determined by the CPU, there are two modes, tick scheduling and preemption scheduling.

~ Time-sharing scheduling

All threads take turns using the CPU usage, averaging the time each thread consumes the CPU.

-Preemptive scheduling

Prioritize high-priority threads to use the CPU, and if the threads have the same priority, then randomly select one (thread randomness), which Java uses for preemptive scheduling.

How thread series one thread works

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: 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.