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.

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.

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语言中,并发主要指的是线程,但是进程也非常重要。
一个计算机系统通常有很多活动的线程和进程。准确的说在系统中有且只有一个核心的执行程序,在任何一个确定的时间里有且只有一个线程在执行。一个单核的执行周期被很多的进程和线程通过操作系统的时间片特性所共享。
对于计算机操作系统来说,多处理器或者多核已经变得越来越普遍。这大大加强了操作系统并发执行进程和线程的能力,但是即使是在单核单处理器上并发也是可以实现的,这并不需要多处理器或者多核。
进程
 一个进程有它自己的执行环境。一个进程通常有一个完整的,基本的运行资源私有集合,特别的,没一个进程有它独自的内存空间。
进程往往被视作应用程序的代名词。然而,用户看到的单个应用可能是多个进程的集合。为了便于进程之间通信,许多操作系统都支持内部进程间通信(IPC),例如管道(pipe)和套接字(socket),IPC不仅是指进程在同一个操作系统之间通信,同时也支持不同的操作系统之间的通信。
大多数基于java虚拟机的应用程序是单进程的。一个java程序能够通过processbuilder对象来增加进程。多进程的应用程序超出了本课程。
线程
线程有时候被称作轻量级的进程。进程和线程都提供了一个可执行的环境,但是线程相比进程需要较少的资源。
线程包含于进程之中——没一个进程至少需要一个线程。线程共享进程的资源,包括内存,打开的文件。这使得通信是高效而且隐蔽的。
多线程是java平台的一个基本特征。每一个程序至少有一个线程,如果算上系统的内存管理,信号通信等线程的话那么会更多。但是从一个程序员角度来看,你只开启一个了线程,叫做主线程。这个线程具有创建新线程的能力,我们下节再介绍。

【翻译二】java--并发之进程与线程的更多相关文章

  1. Java中的进程和线程

     Java中的进程与线程 一:进程与线程 概述:几乎任何的操作系统都支持运行多个任务,通常一个任务就是一个程序,而一个程序就是一个进程.当一个进程运行时,内部可能包括多个顺序执行流,每个顺序执行流就是 ...

  2. Java中的进程与线程(总结篇)

    详细文档: Java中的进程与线程.rar 474KB 1/7/2017 6:21:15 PM 概述: 几乎任何的操作系统都支持运行多个任务,通常一个任务就是一个程序,而一个程序就是一个进程.当一个进 ...

  3. java 获取当前进程id 线程id

    java  获取当前进程id  线程id RuntimeMXBean (Java Platform SE 8 ) https://docs.oracle.com/javase/8/docs/api/j ...

  4. Java 多线程详解(二)------如何创建进程和线程

    Java 多线程详解(一)------概念的引入:http://www.cnblogs.com/ysocean/p/6882988.html 在上一篇博客中,我们已经介绍了并发和并行的区别,以及进程和 ...

  5. Java并发编程:进程和线程的由来(转)

    Java多线程基础:进程和线程之由来 在前面,已经介绍了Java的基础知识,现在我们来讨论一点稍微难一点的问题:Java并发编程.当然,Java并发编程涉及到很多方面的内容,不是一朝一夕就能够融会贯通 ...

  6. JAVA基础知识|进程与线程

    一.什么是进程?什么是线程? 操作系统可以同时支持多个程序的运行,而一个程序可以狭义的认为就是一个进程.在一个进程的内部,可能包含多个顺序执行流,而每个执行流就对应一个线程. 1.1.进程 进程:是计 ...

  7. (转)java中的进程与线程

    (转自地址http://www.ibm.com/developerworks/cn/java/j-lo-processthread/) Java 进程的建立方法 在 JDK 中,与进程有直接关系的类为 ...

  8. Java多线程之进程和线程

    在并发编程中有两个基本的概率就是进程和线程.在Java编程中并发编程更多的是关注线程.但是进程也是很重要的. 一个计算机一般会有很多活跃的进程和线程.有一点是没有疑问的在单核系统中,任何时候实际上都是 ...

  9. java中的进程与线程及java对象的内存结构【转】

    原文地址:http://rainforc.iteye.com/blog/2039501   1.实现线程的三种方式:   使用内核线程实现     内核线程(Kernel Thread, KLT)就是 ...

随机推荐

  1. centos7 开机/etc/rc.local 不执行的问题

    最近发现centos7 的/etc/rc.local不会开机执行,于是认真看了下/etc/rc.local文件内容的就发现了问题的原因了 #!/bin/bash # THIS FILE IS ADDE ...

  2. Graphic32中TBitmap32.TextOut性能分析[转载]

    转载:http://blog.csdn.net/avan_lau/article/details/6958497 最近在分析软件中画线效率问题,发现在画一些标志性符号的方法,存在瓶颈,占用较大的时间. ...

  3. pycharm3.4 下svn 项目checkout&配置

    pycharm 社区版: 3.4 1. checkout 项目 注意,之前配置好:设置里面的一些配置:(以下勾勾不要勾上) 2. checkout 项目之后,做以下操作: vcs ->enabl ...

  4. 越狱后的ios如何用apt-get 安装各种命令

    越狱后的ios如何用apt-get 安装各种命令   iphone越狱后想玩linux. 1. ssh 客户端:ssh Term Pro. 2. 只装客户端是连不上的,还得一个 ssh connect ...

  5. history/location操作 /navigator 操作/ screen操作

    话说mac真的没广告...就凭这点,mac完胜.ei capitan 好牛畅,分屏很好用啊,回不去了. var hist=window.history; hist.go(param); // para ...

  6. spring + myBatis 常见错误:SQL语法错误

    在程序运行时,有时候会出现如下错误: 这个错误通常是你的sqlmapper.xml中sql语句语法有错误.所以请仔细查看你sql语句是否正确,比如{#id}这样写就会报上述错误,其实应该#{id}这样 ...

  7. 关于MySQL count(distinct) 逻辑的一个bug【转】

    本文来自:http://dinglin.iteye.com/blog/1976026#comments 背景 客户报告了一个count(distinct)语句返回结果错误,实际结果存在值,但是用cou ...

  8. java sleep() 、yield()

    1.sleep() 使当前线程(即调用该方法的线程)暂停执行一段时间,让其他线程有机会继续执行,但它并不释放对象锁.也就是说如果有synchronized同步快,其他线程仍然不能访问共享数据.注意该方 ...

  9. HDU 3111 Sudoku(精确覆盖)

    数独问题,输入谜题,输出解 既然都把重复覆盖的给写成模板了,就顺便把精确覆盖的模板也写好看点吧...赤裸裸的精确覆盖啊~~~水一水~~~然后继续去搞有点难度的题了... #include <cs ...

  10. 【opencv】图片标注文字

    IplImage* pstImg; HI_CHAR as8Title[25];CvFont stTimeFont;//字体信息cvInitFont(&stTimeFont,CV_FONT_HE ...