Java Processes and Threads 進程與線程

來源:互聯網
上載者:User

標籤:

Processes and Threads

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.

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.

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.

Processes

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.

一個進程有自己獨立啟動並執行環境和資源。

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進行通訊的。

Most implementations of the Java virtual machine run as a single process. A Java application can create additional processes using aProcessBuilder object. Multiprocess applications are beyond the scope of this lesson.

Threads

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.

線程通常被看為一個輕量級的進程,進程和線程都有一個啟動並執行環境,但是建立一個線程需要的資源更少。

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平台啟動並執行基本特徵。


Java Processes and Threads 進程與線程

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.