JAVA Multithreading and Concurrency Learning notes (i)

Source: Internet
Author: User

One, process and thread

 1. Process

When a program goes into memory run, it becomes a process. A process is a program that is in the process of running. A process is an independent unit of the operating system for resource allocation and scheduling. Three characteristics of a process:

    • Independence

Entities that exist independently, each with its own private piece of memory space.

    • Dynamic nature

A program is just a static set of instructions, and a process is a collection of instructions that are active in the system.

    • Concurrency of

Multiple processes can execute concurrently on a single processor.

  2. Threads

A thread is the smallest unit that the operating system can perform operations on, which is included in the process and is the actual operating unit of the process. Threads are also known as lightweight processes. Threads are independent, concurrent execution streams in the process.

  3. The difference between threads and processes

Threads are part of a process, a process can have many threads, and each thread performs different tasks in parallel. Different processes use different memory spaces, and threads share all of the resources owned by the parent process with other threads of the parent process. It's easy to program, but be more careful. Do not confuse the memory space with the stack memory, each with a separate stack memory to store the local data. Threads have their own stacks, their own program counters, and their own local variables, but do not own system resources. The scheduling and management of threads is done by the process itself. The operating system schedules, manages, and allocates resources to the process.

  4. Concurrency and parallelism

Concurrency means that only one instruction can be executed at the same point in time, but multiple process instructions are executed quickly, making it possible for the macro to have more than one process concurrently executing the effect.
Parallel means that at the same point in time, multiple instructions are executed concurrently on multiple processors

Second, the advantages of multithreading

Memory cannot be shared between processes, but memory is shared between threads. The system needs to reallocate system resources for the process when it is created, but it is much less expensive and efficient to create threads. Multithreading has the following advantages:

    • Better resource utilization
    • Programming is easier in some cases
    • Faster program Response

JAVA Multithreading and Concurrency Learning notes (i)

Related Article

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.