Java Multithreading Summary

Source: Internet
Author: User

The process is a program in execution, the program is static (we do not run it after writing to keep it there), the process is the implementation of the program, is a dynamic concept. A process can have multiple threads.

Two. Multithreading contains two or more than two concurrently running parts, which are called threads for each of these concurrently running parts of a program.

1. Process-based multitasking means that you allow your computer to run two or more programs at the same time.

2. Thread-based multitasking means that a program can perform two more tasks.

Three. How Java threads are implemented:

1. Extends Thread and rewrite the Run () method.

2. Implements Runnable interface, pass the object implementing the Runnable interface as a parameter to the new Thread (new Runnable () {public void Run () {}});

  Start a thread call the start () method, not the run () method!!!!!! The start () method first prepares the system resources for the execution thread and then calls the run () method of the Runnable interface. When a category inherits the thread or implements the Runnable interface, the class is called a thread class.

Four. Stop a running thread do not use the Stop () method, with a variable to control.

Five. The life cycle of a thread:

1. Create a status: New A Thread class object, the system does not allocate resources;

2. Operational status: Call the Start () method to allocate resources, so that the thread class object has a running condition, if the CPU time slice, then the thread into a running state (everything is ready, only the time slice);

3. Non-operational status: the thread block or time slice is exhausted, the block becomes operational after completion, the time slice runs out and becomes operational again, waiting for the time slice to be allocated again;

4. Extinction status: Thread end;

Java Multithreading Summary

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.