java线程和操作系统线程
线程数 (Threads)
A thread is a unit of CPU utilization, which comprises the following parts that are program counter, register set, stack and a thread ID. Generally, it’s well known that the process is heavy weighted which means they consume lot more resources than the threads, and in this threads are light weighted. Basically, there are two types of threading process are there which are as follows:
线程是CPU利用率的单位,包括以下部分:程序计数器,寄存器集,堆栈和线程ID。 通常,众所周知,进程的权重很重,这意味着它们比线程消耗更多的资源,而在这种情况下,线程的权重很轻。 基本上,有两种类型的线程处理过程,如下所示:
Single Threaded process:
单线程进程:
Traditionally if a process has a single thread of control then it is termed as a single threaded process.
传统上,如果进程具有单控制线程,则将其称为单线程进程。
Multi Threaded process:
多线程进程:
If a process has multiple threads of control then it is termed as a Multithreaded process. It can be used to perform multiple tasks at a single time.
如果一个进程具有多个控制线程,则将其称为多线程进程。 它可以一次执行多个任务。
Thread also plays a vital role in RPC which means Remote procedure call. It is used to call a function of some another program. The thread can also be used for the interprocess communication.
线程在RPC中也起着至关重要的作用,这意味着远程过程调用。 它用于调用另一个程序的功能。 该线程也可以用于进程间通信。
多线程编程的好处 (Benefits of Multi-Threaded programming)
Responsiveness:
响应能力:
Since multithreading is an application which will allow a program to run even when a part of it is blocked. So it will increase the responsiveness to the particular user. For example suppose that a particular section is not responding in the above Multi-Threaded diagram instead of an entire process not responding, the two sections can respond to the user, which means Responsiveness.
由于多线程是一个应用程序,即使其中一部分被阻止,它也将允许程序运行。 因此,它将增加对特定用户的响应。 例如,假设在上面的多线程图中特定部分没有响应,而不是整个过程没有响应,则这两个部分可以响应用户,这意味着响应性。
Resource sharing:
资源共享:
It is a beneficial part in case of Multi-Threaded programming as it allows an application to have several different threads of venture within the same address space.
在多线程编程的情况下,它是有益的部分,因为它允许应用程序在同一地址空间内具有多个不同的冒险线程。
Boom Throughput:
动臂吞吐量:
Number of jobs completed per unit time is increased which is a favorable condition.
每单位时间完成的作业数量增加,这是一个有利条件。
Communication:
通讯:
As different threads have the same address space so it is very easier to communicate with the Multiple-Thread.
由于不同的线程具有相同的地址空间,因此与多线程通信非常容易。
Economy:
经济:
As we know that threads share resources of the process for which they belong, by this it will be more economical to create threads for data and resource sharing.
众所周知,线程共享它们所属进程的资源,因此,创建用于数据和资源共享的线程将更加经济。
Utilization of the Multiprocessor architectures:
多处理器体系结构的利用:
The benefits of Multi-Threading can be increased in an architecture which means threads can be made to run in parallel on a different processor, thus there will increment in a concurrency level.
在体系结构中可以增加多线程的好处,这意味着可以使线程在不同的处理器上并行运行,因此并发级别会增加。
多线程模型 (Multithreading Models)
Generally, there are two types of threads which are user thread and another one is kernel thread. In this type of system, the user-level threads are supported above the kernel and managed without kernel support, whereas kernel threads are directly supported and managed by the help of an operating system. On the basis of it there are generally three types of model governed:
通常,有两种类型的线程是用户线程,另一种是内核线程。 在这种类型的系统中,用户级线程在内核之上受支持并且在没有内核支持的情况下进行管理,而内核线程在操作系统的帮助下直接得到支持和管理。 在此基础上,通常管理三种类型的模型:
Many to One model
多对一模型
In this mapping is done between the many user-level threads to the one kernel thread. So in this, we have many user levels which are mapped with one kernel thread.
在这种情况下,映射是在许多用户级线程到一个内核线程之间完成的。 因此,在此,我们有许多用户级别,它们被一个内核线程映射。
One to One Model
一对一模型
In this mapping is done between each user thread and the kernel thread.
在此,在每个用户线程和内核线程之间完成映射。
Many to Many Model
多对多模型
It is a type of model in which it multiplexes many user-level threads to a smaller or equal number of kernel threads. In this, if we have four user threads than we can have either four or less than four kernel thread.
它是一种模型,其中它将许多用户级线程多路复用为更少或相等数量的内核线程。 在这种情况下,如果我们有四个用户线程,那么我们可以有四个或少于四个内核线程。
翻译自: https://www.includehelp.com/operating-systems/threading.aspx
java线程和操作系统线程