`
aahyhaa
  • 浏览: 7822 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

java线程和操作系统进程的关系

    博客分类:
  • Java
阅读更多


One very straightforward way to implement concurrency is at the operating system level, using processes. A process is a self-contained program running within its own address space. A multitasking operating system can run more than one process (program) at a time by periodically switching the CPU from one process to another, while making it look as if each process is chugging along on its own.Processes are very attractive because the operating system usually isolates one process from another so they cannot interfere with each other, which makes programming with processes relatively easy. In contrast, concurrent systems like the one used in Java share resources like memory and I/O, so the fundamental difficulty in writing multithreaded programs is coordinating the use of these resources between different thread-driven tasks, so that they cannot be accessed by more than one task at a time.


Java took the more traditional approach of adding support for threading on top of a sequential language. Instead of forking external processes in a multitasking operating system, threading creates tasks within the single process represented by the executing program. One advantage that this provided was operating system transparency, which was an important design goal for Java. For example, the pre-OSX versions of the Macintosh operating system (a reasonably important target for the first versions of J ava) did not support multitasking. Unless multithreading had been added to J ava, any concurrent Java programs wouldn’t have been portable to the Macintosh and similar platforms, thus breaking the "write once/run everywhere" requirement.


Concurrent programming allows you to partition a program into separate, independently running tasks. Using multithreading, each of these independent tasks (also called subtasks) is driven by a thread of execution. A thread is a single sequential flow of control within a process. A single process can thus have multiple concurrently executing tasks, but you program as if each task has the CPU to itself. An underlying mechanism divides up the CPU time for you, but in general, you don’t need to think about it.The threading model is a programming convenience to simplify juggling several operations at the same time within a single program: The CPU will pop around and give each task some of its time. Each task has the consciousness of constantly having the CPU to itself, but the CPU’s time is being sliced among all the tasks (except when the program is actually running on multiple CPUs). One of the great things about threading is that you are abstracted away from this layer, so your code does not need to know whether it is running on a single CPU or many. Thus, using threads is a way to create transparently scalable programs—if a program is running too slowly, you can easily speed it up by adding CPUs to your computer. Multitasking and multithreading tend to be the most reasonable ways to utilize multiprocessor systems.

分享到:
评论

相关推荐

    用java编的适用于操作系统课程设计的线程-进程管理

    用java编的适用于操作系统课程设计的线程-进程管理

    java语言操作系统课程设计模拟进程管理系统源码.zip

    java语言操作系统课程设计模拟进程管理系统源码 需求分析 实现n个进程并发运行; 实现进程创建、撤销、阻塞、唤醒; 实现进程的同步; 实现优先级调度、时间片轮转、短进程优先等调度算法; 系统在运行过程中应能...

    java多线程笔记

    一、操作系统中线程和进程的概念 2 二、Java中的线程 3 三、Java中关于线程的名词解释 3 四、线程的状态转换和生命周期 4 Java线程:创建与启动 7 Java线程:线程名称的设定及获取 10 Java线程:线程栈模型与线程的...

    Java多线程编程经验

    现在的操作系统是多任务操作系统。多线程是实现多任务的一种方式。 线程是指进程中的一个执行流程,一个进程中可以运行多个线程。比如java.exe进程中可以运行很多线程。线程总是属于某个进程,进程中的多个线程共享...

    4种常用Java线程锁的特点,性能比较、使用场景.pdf

    4种常用Java线程锁的特点,性能比较、使用场景 线程(thread)是操作系统能够进行运算调度的最小单位。它被包含在进程之中,是进程中的实际运作单位。一条线程指的是进程中一个单一顺序的控制流,一个进程中可以并发...

    进程与线程_动力节点Java学院整理.

    本文首先简单的介绍如何使用这些类来创建进程和线程,然后着重介绍这些类是如何和操作系统本地进程线程相对应的,给出了 Java 虚拟机对于这些封装类的概要性的实现;同时由于 Java 的封装也隐藏了底层的一些概念和可...

    操作系统,多线程编程,多进程编程,java

    用java实现的操作系统多线程编程,用Eclipse编写。内有实验指导书,导入绝对能运行。

    Java多线程编程指南

    这里定义和线程相关的另一个术语 - 进程:一个进程包括由操作系统分配的内存空间,包含一个或多个线程。一个线程不能独立的存在,它必须是进程的一部分。一个进程一直运行,直到所有的非守护线程都结束运行后才能...

    操作系统——实验四 windows中线程的创建和同步控制

    在windows的环境下,创建一个控制台进程,此进程创建两个并发线程,一个是读线程,另一个是写线程。这两个线程共享一个数组A,写线程对数组分别进行10次写操作,每次写操作对A的每个元素赋一个相同的值;读线程对数组...

    Java线程详解.ppt

    在创建、撤销和切换,系统需要付出较大的开销,因此,系统中设置的进程不能太多, 进程切换的频率也不能过高,这就限制了并发程度的提高。 为了解决这一问题,于是产生并引入了线程概念。 一个进程中可以包含...

    操作系统中的进程、线程与Java的多线程.pdf

    操作系统中的进程、线程与Java的多线程

    Java_多线程与并发编程总结.doc

    对于一个进程中的多个线程来说,多个线程共享进程的内存块,当有新的线程产生的时候,操作系统不分配新的内存,而是让新线程共享原有的进程块的内存。因此,线程间的通信很容易,速度也很快。不同的进程因为处于不同...

    图解java多线程

    本文主要讲java中多线程的使用方法、线程同步、线程数据传递、线程状态及相应的线程函数用法、概述等。首先让我们来了解下在操作系统中进程和线程的区别:

    Java多线程之进阶篇(一).docx

    多任务操作系统可以通过周期性地将CPU从一个进程切换到另一个进程,来实现同时运行多个(进程)程序,尽管使得每个线程看起来在其执行过程都是歇歇停停。进程被操作系统互相隔开,因此不会彼此干涉,这使得用进程...

    解析Java的多线程机制

    Unix操作系统环境下,应用程序可以利用fork函数创建子进程,但子进程与该应用程序进程拥有独立的地址空间、系统资源和代码执行单元,并且进程的 调度是由操作系统来完成的,使得在应用进程之间进行通信和线程协调...

    java学习多线程处理

    线程的分类:系统级线程(又称为核心级线程,负责管理调度不同进程之间的多个线程,由操作系统直接管理) 用户级线程(仅存在于用户空间,在应用程序中控制其创建,执行和消亡) 多线程开发的优势:改善用户体验,...

    Java多线程之基础篇(一).docx

    多任务操作系统可以通过周期性地将CPU从一个进程切换到另一个进程,来实现同时运行多个(进程)程序,尽管使得每个线程看起来在其执行过程都是歇歇停停。进程被操作系统互相隔开,因此不会彼此干涉,这使得用进程...

    Java 操作系统课设之模拟进程管理系统

    Java 操作系统课设之模拟进程管理系统。 使用Java实现的操作系统课设之模拟进程管理系统,是博主的一个课设,emmm 进程管理系统 操作系统课设 Java

    Java线程总结教程

    在论坛上面常常看到初学者对线程的无可奈何,所以总结出了下面一篇文章,希望对一些正在学习使用java线程的初学者有所帮助。 首先要理解线程首先需要了解一些基本的东西,我们现在所使用的大多数操作系统都属于多...

    进程和线程的创建 _实验报告.doc

    1.在linux下编写一个应用程序,命名为an_ch2_1b。这个程序不断地输出如下行: ...而新创建的线程则不断地对shared_var 进行减1 操作,即每次循环shared_var 被减1。观察程序运行的结果,并对你看到的现象进行解释。

Global site tag (gtag.js) - Google Analytics