JAVA Learning Summary Multithreading

Source: Internet
Author: User

1 What is a thread

A thread is a sequential flow control within a program. The thread itself cannot run. It can only be used in programs, using resources and environments that are assigned to programs.

2 The difference between a process and a thread

  • The internal data and state of multiple processes are completely independent, and multithreading is a shared piece of memory space and a set of system resources that may interact with each other.
  • The data of the thread itself is usually only the register data, and a program executes the stack that is used, so the thread switching is less burdensome than the process switching.

3 Multi-Threading

Multithreading refers to the ability to run multiple different threads at the same time in a single program to perform different tasks.

  • A process can contain one or more threads.
  • A program that implements multiple code runs concurrently requires multithreading.
  • The CPU randomly takes the time to get our program to do this one thing and do another thing.

4 purpose of multi-threading

Is "Maximize CPU resources", when a thread processing does not need to occupy the CPU, but only with resources such as I/O, so that other threads that need to consume CPU resources have the opportunity to gain CPU resources. This is the ultimate goal of multithreaded programming.

5. Single Thread

  • When the program starts running, it automatically generates a thread, and the main method is run on this thread.
  • Our programs are executed by the thread.

JAVA Learning Summary Multithreading

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.