(本部分原文连接,译文连接,译者:bjsuo,校对:郑旭东)
In concurrent programming, there are two basic units of execution: processes and threads. In the Java programming language, concurrent programming is mostly concerned with threads. However, processes are also important.html
在并发编程中,有两个基本的执行单元:进程和线程。在Java语言中,并发编程最关心的是线程,然而,进程也是重要的。
A computer system normally has many active processes and threads. This is true even in systems that only have a single execution core, and thus only have one thread actually executing at any given moment. Processing time for a single core is shared among processes and threads through an OS feature called time slicing.java
一个计算机系统一般有许多活动的进程和线程。这是事实,即使是在只有单一执行核心的计算机系统中,所以,在任何给定的时刻,只有一个线程在实际执行。单核处理器的处理时间是经过操做系统的时间切片在进程和线程之间共享的。
It's becoming more and more common for computer systems to have multiple processors or processors with multiple execution cores. This greatly enhances a system's capacity for concurrent execution of processes and threads — but concurrency is possible even on simple systems, without multiple processors or execution cores.程序员
如今具备多处理器或有多执行内核的多处理器的计算机系统愈来愈广泛,这大大加强了系统并发执行的进程和线程的吞吐量–但在没有多个处理器或执行内核的简单的系统中,并发仍然是可能的。
编程
进程
A process has a self-contained execution environment. A process generally has a complete, private set of basic run-time resources; in particular, each process has its own memory space.api
进程具备一个独立的执行环境。一般状况下,进程拥有一个完整的、私有的基本运行资源集合。特别地,每一个进程都有本身的内存空间。
Processes are often seen as synonymous with programs or applications. However, what the user sees as a single application may in fact be a set of cooperating processes. To facilitate communication between processes, most operating systems support Inter Process Communication (IPC) resources, such as pipes and sockets. IPC is used not just for communication between processes on the same system, but processes on different systems.多线程
进程每每被看做是程序或应用的代名词,然而,用户看到的一个单独的应用程序实际上多是一组相互协做的进程集合。为了便于进程之间的通讯,大多数操做系统都支持进程间通讯(IPC),如【管道】pipes 和【插座】sockets。IPC不只支持同一系统上的通讯,也支持不一样的系统。
Most implementations of the Java virtual machine run as a single process. A Java application can create additional processes using a ProcessBuilder
object. Multiprocess applications are beyond the scope of this lesson并发
Java虚拟机的大多数实现是单进程的。Java应用可使用ProcessBuilder对象建立额外的进程,多进程应用超出了本课的范围。
oracle
线程
Threads are sometimes called lightweight processes. Both processes and threads provide an execution environment, but creating a new thread requires fewer resources than creating a new process.
app
线程有时也被称为轻量级的进程。进程和线程都提供了一个执行环境,但建立一个新的线程比建立一个新的进程须要的资源要少。 less
Threads exist within a process — every process has at least one. Threads share the process's resources, including memory and open files. This makes for efficient, but potentially problematic, communication.
线程是在进程中存在的 — 每一个进程最少有一个线程。线程共享进程的资源,包括内存和打开的文件。这样提升了效率,但潜在的问题就是线程间的通讯。
Multithreaded execution is an essential feature of the Java platform. Every application has at least one thread — or several, if you count "system" threads that do things like memory management and signal handling. But from the application programmer's point of view, you start with just one thread, called the main thread. This thread has the ability to create additional threads, as we'll demonstrate in the next section.
多线程的执行是Java平台的一个基本特征。每一个应用都至少有一个线程 – 或几个,若是算上“系统”线程的话,好比内存管理和信号处理等。可是从程序员的观点来看,启动的只有一个线程,叫主线程。这个线程有能力建立额外的线程,咱们将在下一节演示。