(本部分原文連接,譯文連接,譯者: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平臺的一個基本特徵。每一個應用都至少有一個線程 – 或幾個,若是算上「系統」線程的話,好比內存管理和信號處理等。可是從程序員的觀點來看,啓動的只有一個線程,叫主線程。這個線程有能力建立額外的線程,咱們將在下一節演示。