Song lixing _ Chapter 1 multi-thread Section 1

Source: Internet
Author: User

Chapter 1 multithreading Section 1 notes

1,Program: A staticCode.

Process: a dynamic execution process of a program, which corresponds to a complete process from code loading, execution to execution.

A process is also called a task. an OS that supports simultaneous execution of multiple processes is called

2. In a program, multiple tasks can be concurrently executed, and each task is called a thread.

A thread is a smaller execution unit than a process. It is an independent control flow in a process, that is, the control flow inside the program.

Features: The thread cannot be run independently and must depend on the process to run in the process.

Each program has at least one thread called the main thread.

Single thread: multiline Name:

Advantage: Improves the interface response speed. Make full use of system resources. Disadvantages:

1. inherit from the Thread class.

Java. lang 1> class name extends thread, new object, thread new status, start ()-start thread-thread ready, wait for the object to wait in the ready queue. 2. Put the code of the task completed by the thread in the run () method, and rewrite the run () method.

Thread features: Random. When the system executes a multi-line name

2. Implement the runnable interface // avoids multiple inheritance

Multiple Threads implement the runnable interface to create thread objects. Create a thread object with the object as the parameter and start the thread. Thread object. Start () method start thread wait CPU time slice, sleep () (enter sleep mode) method/Wait () method to let out CPU resources. Wait for the CPU resource to be obtained. Create-start () --> ready-CPU available-> Run-> dead/blocked (BLOCKED)

Thread Java.

3. Use timer and timertask combination. ---->

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.