zoukankan      html  css  js  c++  java
  • Processes and Threads

    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.
    在并发编程中,有2个基本的执行单元:进程和线程。在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.
    计算机系统中一般会有很多活动的进程和线程。甚至在单核系统中也是如此,因此在任何时刻仅仅只有一个线程实际在运行。单核的处理时间通过一种叫做分时(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.
    一个进程拥有一个独立的运行环境。一个进程通常拥有一套完整的,私有的基础运行时资源(run-time resources);尤其是每个进程都有自己的内存空间。
    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)和套接字(socket) 。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.
    大部分的jvm实现是作为单进程运行。一个java程序可以用ProcessBuilder创建额外的进程。多进程应用程序不在本课的范围之内。
    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平台的一个基本功能。每个应用程序都至少有个线程-或多个,如果算上内存管理和信号处理的系统线程。但是以应用程序员的看法,你只是启动了一个叫做main的线程。这个线程有创建额外线程的能力。这些我们将在下一个章节介绍。

  • 相关阅读:
    python 时间差计算
    NET Framework 4.5新特性 (一) 数据库的连接加密保护。
    某表含有N个字段超精简模糊查询方法
    清空javascript数组数据
    IIS无法连接LocalDb,怎么办?
    jquery 模糊查询对象属性
    解释杨中科随机数为什么会骗人?
    前端Js传递数组至服务器端
    javascript获取客户端默认打印机
    水晶报表注意的问题
  • 原文地址:https://www.cnblogs.com/yuwenxing/p/2502295.html
Copyright © 2011-2022 走看看