Java thread _ 01

Source: Internet
Author: User

    Thread?

  1. Command sequence that can be executed in parallel
  2. Minimum unit that can be scheduled by the operating system
  3. A thread can also be understood as a lightweight process.
  4. Generally, a thread is contained in a process.
  5. A process can contain multiple threads. Normally, these threads share resources with each other.
  6. Threads can run simultaneously on multiple core CPUs, and the number of threads running simultaneously is affected by the number of cores.
  7. Threads run on a single-core CPU in time, because it is fast enough and we don't feel any problems.

Application scenarios of threads

  1. To process and execute asynchronous tasks, multiple real-time charts are usually displayed under a single panel in the GUI.
  2. The computation speed is faster and the existing popular dual-core or multi-core CPU is used properly.
  3. Non-blocking, scheduled tasks, I/O, scheduling, and regular detection.
  4. Parallelize: parallelizable algorithms. For example, each cycle branch is executed on different CPUs step by step. However, because the data in each cycle is dependent, the implementation method varies depending on the specific scenario.
  5. The response of the application gives us the illusion that the program performance is very good, but it does make us work more smoothly.

Basic Concepts

  1. Virtual Memory, the operating system abstracts all accessible primary storage resources
  2. CPU mode, real mode, and protection mode
  3. In kernel space and CPU protection mode, the operating environment of the system is protected, so the virtual memory space is separated. Kernel space is not involved in system virtual memory management. It will stay in the memory in the SWAp-in and swap-out mode.
  4. User space, which is a virtual memory space for non-kernel applications,

 

Processes and threads

A process is a heavyweight system kernel scheduling unit. It has resources allocated to it by the operating system, such as memory, file handles, and device.
Handles and sockets. Generally, a process does not share the address space and resources unless it uses clear methods such as Inherited Resource handles or shared memory segments.

With the development and evolution of the operating system, processes evolve into the objects for allocating and managing operating system resources, while the minimum unit for Operating System Scheduling and execution evolves into threads.

Kernel thread

  1. The kernel thread is the minimum unit for Kernel scheduling and execution.
  1. Each process has at least one kernel thread.
  1. If a process allows multiple kernel threads, these kernel threads will share resources (memory, file
    Handles)
  1. Kernel threads have their own internal non-shared resources (stacks, program counters, and internal storage space ).
  2. The system kernel allocates a thread to each logic core, which can switch blocked threads from the logic core.
  3. The kernel thread requires more time to exchange than the user thread.

User thread

  1. User threads run in user space
  2. The operating system supports threads by adding a Runtime Library in the user space.
  3. The Runtime Library is responsible for user Thread Scheduling and execution, creation and destruction, message transmission among multiple user threads, and user thread context management.
  4. The kernel does not perceive the existence of user threads, and scheduling and management of user threads are carried out in the user space.
  5. The communication between user threads and kernel threads is added to the concept of lightweight processes (lwp.
  6. Green thread refers to implementing user threads through virtual machine technology

Optical Fiber

  1. Smaller and more flexible than Process Units
  2. Fiber does not participate in kernel Scheduling
  3. The scheduling and execution of the fiber process are independently controlled by the application.

 

User thread, kernel thread, Lightweight Process

  • 1. There is a ing between user threads and kernel threads.

     

  • 2. JVM thread model
    • There is a thread ing relationship between the kernel thread and the user space.
    • JVM has only one kernel thread in the kernel space.
    • The threads created by JVM in the user space can be different based on the operating system, but it can also be understood that the threads created in the user space are user-level transparent to the kernel.

     

    Query Materials

    1. Http://en.wikipedia.org/wiki/Thread_ (Computing)
    1. Http://www.cnblogs.com/gutian98/archive/2009/09/03/1559560.html
    1. Http://www.linuxforum.net/forum/showflat.php? Board = linuxk & number = 451275
    2. Http://zhidao.baidu.com/question/198207122.html
    1. Java thread 3th
    1. User thread
    2. Logical Address \ linear address \ virtual address
    3. Kernel thread and user thread
    4. Relationship between kernel threads and user threads
    1. Http://www.baidu.com
  • 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.