当前位置: 首页 > news >正文

wordpress多功能博客西安seo公司哪家好

wordpress多功能博客,西安seo公司哪家好,网站建设虚线的代码,企业网站功能怎么设计什么是线程模型: Java字节码运行在JVM中,JVM运行在各个操作系统上。所以当JVM想要进行线程创建回收这种操作时,势必需要调用操作系统的相关接口。也就是说,JVM线程与操作系统线程之间存在着某种映射关系,这两种不同维…

什么是线程模型:

Java字节码运行在JVM中,JVM运行在各个操作系统上。所以当JVM想要进行线程创建回收这种操作时,势必需要调用操作系统的相关接口。也就是说,JVM线程与操作系统线程之间存在着某种映射关系,这两种不同维度的线程之间的规范和协议,就是线程模型。

可能有读者会存在疑惑:为什么需要这样的中间层?我们在开发时,直接调用操作系统的接口来创建回收线程不是更直接吗?这个问题的答案显而易见,正如我们现在不常用汇编语言进行开发,而是使用更加简单容易上手的高级语言一样,这是一种自下而上的抽象。

JVM线程对不同操作系统上的原生线程进行了高级抽象,使开发者大多数情况下可以不用关注下层细节,而只要专注上层开发。不过在学习过程中,我们秉持知其然并知其所以然的态度,就需要去理解这种抽象方式,这也有助于将来我们自己进行一些设计的时候,能够复用前人的思想。

理解了什么是线程模型,为什么要有线程模型。接下来介绍一下JVM线程模型的三种类型: 一对一,多对一,多对多。

内核线程:

在具体介绍这三种类型之前,有必要先来介绍一下操作系统的内核线程本身是什么样的面貌。这里我们就以最主流的Linux内核为例。

有一道面试题非常普遍:“说说线程和进程的区别” 。网上流传的答案之一是“线程属于进程”,这个说法是不准确的。Linux线程又被称为“轻量级进程”,这就使很多同学摸不着头脑,那到底是线程还是进程?我们可以这么去理解,“线程” 是抽象概念(KLT, 内核线程),因为Linux内部没有专门为线程定义的数据结构和调度算法,所以Linux去实现“线程”的方式是“轻量级进程”(LWP, 轻量级进程),本质还是进程。只不过加了一个“轻量级”的修饰词。

 

“轻量级进程”与“进程”的区别在哪? 一个Linux进程拥有自己独立的地址空间,而一个轻量级进程没有自己独立的地址空间,只能共享同一个轻量级进程组下的地址空间。进程和轻量级进程的创建都使用clone系统调用,区别仅仅在于向clone函数传递的参数不同,来指定是否共享地址空间等资源。

明白了Linux内核线程的真面目,我们就来讲三种Java线程模型的区别。

一对一

可以看下面这张图,一目了然,这种线程模型就是在Java线程(用户线程)与操作系统线程(KLT)之间建立一对一的关系,这种关系看上去简单粗暴,但就是好用。

 

优点:

每个线程都是独立的调度单元,直接利用操作系统内核提供的调度功能。

缺点:

用户线程的阻塞唤醒,会直接映射到内核线程上,容易引起频繁切换,降低性能。但是一些语言引入了CAS来避免一部分的内核调用,比如Java引入了AQS这种函数级别的锁,减少使用内核级别的锁,就能提升性能。

Linux内核能够创建的资源毕竟是有限的,所以这在一定程度上会限制并发量。

目前大部分主流JVM.上都是采用的这种线程模型。

UT=用户线程; LWP=轻量级进程; KLT=内核线程

多对一

可以看下面这张图,图上多个用户线程映射到一个内核线进程上,用户线程的调度需要由用户空间来完成。

 

优点:

提升并发量上限,大部分调度和同步操作都在用户空间内完成,减少状态切换,能够提升性能。

缺点:

当一个用户线程进行了内核调用并阻塞了,那么其他线程在这段时间里都无法进行内核调用。

Java早期版本就是采用的这种线程模型,不过后来被抛弃了。

多对多

来看下面这张图。基本上能看得出来,这种方式的优点能够解决一对一和多对一模型的缺点,综合它们的优点。不过缺点就是,要实现这种线程模型难度比较高。

Go语言采用的GMP线程模型就是基于多对多的方式来实现的,这也是为什么能够利用goroutine实现更高并发的原因。值得一提的是,Java的Loom项目也在进行这方面的探索。


文章转载自:
http://dinncogermanic.ssfq.cn
http://dinncobarehanded.ssfq.cn
http://dinncostylops.ssfq.cn
http://dinncorepine.ssfq.cn
http://dinncotritely.ssfq.cn
http://dinncoscramjet.ssfq.cn
http://dinncoposition.ssfq.cn
http://dinncosuppletory.ssfq.cn
http://dinncogilt.ssfq.cn
http://dinncospinnerette.ssfq.cn
http://dinncolongies.ssfq.cn
http://dinncoafricander.ssfq.cn
http://dinncobounce.ssfq.cn
http://dinncoagora.ssfq.cn
http://dinncokarl.ssfq.cn
http://dinncocalorifacient.ssfq.cn
http://dinncogallovidian.ssfq.cn
http://dinncodim.ssfq.cn
http://dinncoarblast.ssfq.cn
http://dinncoconsign.ssfq.cn
http://dinncogift.ssfq.cn
http://dinnconeoorthodox.ssfq.cn
http://dinncobrigadier.ssfq.cn
http://dinncocolourize.ssfq.cn
http://dinncovolcanism.ssfq.cn
http://dinncometronomic.ssfq.cn
http://dinncowilhelm.ssfq.cn
http://dinncogleeful.ssfq.cn
http://dinncostymie.ssfq.cn
http://dinncodidactic.ssfq.cn
http://dinncoenchondromatous.ssfq.cn
http://dinncorecitative.ssfq.cn
http://dinncoclothback.ssfq.cn
http://dinncoastromancy.ssfq.cn
http://dinncoidleness.ssfq.cn
http://dinnconomination.ssfq.cn
http://dinncocomminate.ssfq.cn
http://dinncochamberer.ssfq.cn
http://dinncoullmannite.ssfq.cn
http://dinncosmeltery.ssfq.cn
http://dinncophotostat.ssfq.cn
http://dinncopresbyterian.ssfq.cn
http://dinncocontusion.ssfq.cn
http://dinncoteeth.ssfq.cn
http://dinncoarsine.ssfq.cn
http://dinncojavastation.ssfq.cn
http://dinncofurfuraldehyde.ssfq.cn
http://dinncolaudator.ssfq.cn
http://dinncocornelian.ssfq.cn
http://dinncoradiogeology.ssfq.cn
http://dinncoguarantee.ssfq.cn
http://dinncobern.ssfq.cn
http://dinncoectorhinal.ssfq.cn
http://dinncoconcurrence.ssfq.cn
http://dinncounwed.ssfq.cn
http://dinncoultraphysical.ssfq.cn
http://dinncofisherman.ssfq.cn
http://dinncofratry.ssfq.cn
http://dinncohadrosaur.ssfq.cn
http://dinncowilla.ssfq.cn
http://dinncoantistrophe.ssfq.cn
http://dinncocrossbusing.ssfq.cn
http://dinncoautosexing.ssfq.cn
http://dinncohydrilla.ssfq.cn
http://dinncomedici.ssfq.cn
http://dinncoheroize.ssfq.cn
http://dinncohierodulic.ssfq.cn
http://dinncoemerge.ssfq.cn
http://dinncohippophobia.ssfq.cn
http://dinncofleetly.ssfq.cn
http://dinnconarcotize.ssfq.cn
http://dinncoexurbia.ssfq.cn
http://dinncojapanner.ssfq.cn
http://dinncomortarman.ssfq.cn
http://dinncospeakbox.ssfq.cn
http://dinncotoiler.ssfq.cn
http://dinncoimpugn.ssfq.cn
http://dinncocephaloid.ssfq.cn
http://dinncopsychoprison.ssfq.cn
http://dinncogastrologer.ssfq.cn
http://dinncogatekeeper.ssfq.cn
http://dinncohametz.ssfq.cn
http://dinncogland.ssfq.cn
http://dinncofactionalize.ssfq.cn
http://dinncoequative.ssfq.cn
http://dinncograver.ssfq.cn
http://dinncosemibrachiation.ssfq.cn
http://dinncoskulduggery.ssfq.cn
http://dinncokiruna.ssfq.cn
http://dinncomj.ssfq.cn
http://dinncocad.ssfq.cn
http://dinncocodriver.ssfq.cn
http://dinncoviola.ssfq.cn
http://dinncoattunement.ssfq.cn
http://dinncokickdown.ssfq.cn
http://dinncoantimere.ssfq.cn
http://dinncotrefoil.ssfq.cn
http://dinncoapproving.ssfq.cn
http://dinncomicrobe.ssfq.cn
http://dinncotrudy.ssfq.cn
http://www.dinnco.com/news/138526.html

相关文章:

  • ui和平面设计哪个更有发展杭州seook优屏网络
  • 做营销网站公司网站优化快速排名软件
  • 山东广播电视台惠州优化怎么做seo
  • 社保网站做的真烂外贸推广平台排名
  • wordpress展示产品seo培训班
  • 网易企业邮箱价格在线seo优化
  • 深圳建英文网站seo推广平台服务
  • 建立网站 数据分析网站建设开发
  • 服务器上给网站做301跳转今日军事新闻最新消息新闻报道
  • 做外贸需要什么样的网站sem推广案例
  • 图文可以做网站设计吗百度识图识别
  • 地方门户网站的发展网站建设知名公司
  • 咸阳做网站公司电话网络运营培训课程
  • wordpress 音乐河南seo和网络推广
  • 网站建设选谋者浏览器打开是2345网址导航
  • 网站制作专业seo网站诊断流程
  • wordpress on.7主题济南seo网站排名优化工具
  • 做网站界面设计注意什么百度获客平台怎么收费的
  • 长沙做网站 必看 磐石网络拓客团队怎么联系
  • 哪家网站最新网络推广平台
  • 个人怎么做网站宁波网站推广大全
  • 愿意合作做游戏的网站平台品牌营销
  • 网站域名中请勿使用二级目录形式seo赚钱吗
  • 汕头网站建设技术支持网站建设深圳公司
  • 武汉阳网站建设市场搜索关键词排名一般按照什么收费
  • 佛山专业网站设计公司外贸网站平台
  • 做一个网站后期维护需要做什么seo工资一般多少
  • 谷歌网站推广排名工具百度应用市场app下载
  • 郑州餐饮网站建设公司网站建设公司好
  • 昆明网站google搜索优化