Java FAQ _01 Basic Concepts (006) _ What is the difference between threads and processes

Source: Internet
Author: User

Click to enter _ more _java thousand ask

1. What is the process?

Process is a program with some independent functions, and the operating system uses the process to divide the work into functional units.

A process is an independent unit of resource allocation and scheduling. It also has a private virtual address space that can be accessed only by the threads it contains.

An application (application) is made up of one or more collaborative processes. For example, the Visual Studio development environment is to use one process to edit the source file and use another process to complete the application that compiles the work.

2. What is a thread?

A thread is one or more execution units that are contained in a process. It can only be attributed to a process and can only access the resources owned by the process.
The smallest unit of execution in a process is an entity in the process, which is the basic unit for the process to dispatch and dispatch independently.

The thread itself does not own system resources and has only a few resources (counters, registers, and stacks) that are essential to the operation, but it can share all the resources owned by the process with other threads of the same process. One thread can create and revoke another thread, which can be executed concurrently between multiple threads in the same process.

When the operating system creates a process, the process automatically requests a thread called the main thread (the first threads). The main thread executes the runtime host, and the runtime host is responsible for loading the CLR (the common language runtime).

3. What are the relationships and differences between threads and processes?

First, processes and processes, like trains and carriages, are not comparable, but they have a certain relevance:

    1. A thread can belong to only one process, while a process may have multiple threads, but at least one thread.
    2. A resource is assigned to a process, and all the threads of the same process share all the resources of that process.
    3. The virtual machine is assigned to a thread, that is, a thread that is actually running on the virtual machine.
    4. Threads need to be synchronized during execution. Synchronization is achieved between threads of different processes using the means of message communication.

If you want to compare processes to threads, you can look at the following:

    1. Scheduling
      ?? Threads as the basic unit of dispatch and allocation, processes as the basic unit of resources

    2. Concurrency of
      ?? Not only can concurrent execution between processes, but also concurrent execution between multiple threads of the same process

    3. Own resources
      ?? A process is an independent unit that owns resources, and threads do not own system resources, but can access resources that belong to the process.

    4. System overhead
      ?? When you create or revoke a process, the cost of the system is significantly greater than the cost of creating or revoking the thread, because the system allocates and reclaims resources for it.

Java FAQ _01 Basic Concepts (006) _ What is the difference between threads and processes

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.