江西师范大学Java语言程序设计课件第6章 Java多线程.ppt

江西师范大学Java语言程序设计课件第6章 Java多线程.ppt

  1. 1、本文档共75页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
第6章 Java多线程 主要内容 线程基本概念 线程状态及生命周期 Java线程的创建 Thread类和Runnable接口 线程调度与优先级 线程的控制和消息传递 线程同步和死锁 守护线程 (Daemon) 程序、进程与线程 程序与进程 程序(program) 是一段静态的代码文件,它是应用软件执行的(描述)蓝本。 进程(Process) 是程序的一次动态执行过程,它依赖于操作系统,从分配内存、加载代码、执行相应操作至完成任务的一个完整过程。 这个过程本身也是动态的:从产生、运行、发展至死亡的过程。 线程 线程是程序内的控制流,与进程相似,但执行单位比进程更小。 线程也称为轻型进程,不同线程间允许任务协作和数据交换。 一个程序在其运行过程中,可以产生多个线程,形成多条执行线索。每条线索,即每个线程也有它自身的产生、存在和消亡的过程。 多线程 多线程是实现程序并发的一种有效手段。 一个进程可以通过运行多个线程来并发地执行多项任务。 多个线程如何调度执行由系统来实现。 线程是程序中的单个执行流,多线程是一个程序 中包含的多个同时运行的执行流 线程与进程比较 进程:内核级的实体。 每个进程有自己的状态、有自己的专用数据段(独立内存资源),包含虚存映象、文件指示符用户ID等。这些结构都在内核空间中,用户程序只有通过系统调用才能访问与改变。 线程:用户级的实体。 线程结构驻留在用户空间中,能够被普通的用户级函数组成的线程库直接访问。寄存器(栈指针,程序计数器)是线程专有的成分。线程间共享数据段 一个进程中的所有线程共享该进程的状态。 线程并行 并行性(Parallelism)是针对多处理器环境而言的,是指两个或多个线程真正同时运行在不同的CPU上。 在多处理器机上,很多不同的线程可以并行运行,或者说是同时运行。 Benefits of Threads Takes less time to create a new thread than a process Less time to terminate a thread than a process Less time to switch between two threads within the same process Since threads within the same process share memory and files, they can communicate with each other without invoking the kernel Multithreading How to Configure Threads Kernel-Level Threads (KLTs) User-Level Threads (ULTs) Hybrid KLTs Kernel maintains context information for both the process and the threads Kernel provides thread control API for applications Scheduling is done on a thread basis Examples of this kind of thread include Win XP/Server, Linux, and OS/2 ULTs All thread management is done on the application level It is supported by a thread library outside the kernel e.g. pthread (POSIX thread) libraries, with all of the threads mapping into a single kernellevel process The kernel is not aware of the existence of threads Combine KLT and ULT Both KLT and ULT have their pro and con By using hybrid strategy, the configuration can take advantages of both If the parallelism of application is logical and needs no hardware support, then use the ULT E.g. In a windowing system, all bu

您可能关注的文档

文档评论(0)

ormition + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档