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

网站建设发展情况seo服务哪家好

网站建设发展情况,seo服务哪家好,成品播放器,网页设计时尚页面原文网址:Java多线程系列--synchronized的原理_IT利刃出鞘的博客-CSDN博客 简介 本文介绍Java的synchronized的原理。 反编译出字节码 Test.java public class Test {private static Object LOCK new Object();public static int main(String[] args) {synchro…

原文网址:Java多线程系列--synchronized的原理_IT利刃出鞘的博客-CSDN博客

简介

        本文介绍Java的synchronized的原理。

反编译出字节码

Test.java

public class Test {private static Object LOCK = new Object();public static int main(String[] args) {synchronized (LOCK){System.out.println("Hello World");}return 1;}
}

先用javac Test.class 编译出class文件
再用javap –c Test.class查看字节码文件

字节码文件:

也就是说,锁是通过monitorenter和monitorexit来实现的。

进入监视器

JVM规范中描述:

    monitorenter:` Each object is associated with a monitor. A monitor is locked if and only if it has an owner. The thread that executes monitorenter attempts to gain ownership of the monitor associated with objectref, as follows: • If the entry count of the monitor associated with objectref is zero, the thread enters the monitor and sets its entry count to one. The thread is then the owner of the monitor. • If the thread already owns the monitor associated with objectref, it reenters the monitor, incrementing its entry count. • If another thread already owns the monitor associated with objectref, the thread blocks until the monitor’s entry count is zero, then tries again to gain ownership. `

翻译:

        每个对象有一个监视器锁(monitor)。当monitor被占用时就会处于锁定状态,线程执行monitorenter指令时尝试获取monitor的所有权,过程如下:

  1. 如果monitor的进入数为0,则该线程进入monitor,然后将进入数设置为1,该线程即为monitor的所有者。
  2. 如果线程已经占有该monitor,只是重新进入,则进入monitor的进入数加1.
  3. 如果其他线程已经占用了monitor,则该线程进入阻塞状态,直到monitor的进入数为0,再重新尝试获取monitor的所有权。

退出监视器

JVM规范中描述:

        monitorexit:  ` The thread that executes monitorexit must be the owner of the monitor associated with the instance referenced by objectref. The thread decrements the entry count of the monitor associated with objectref. If as a result the value of the entry count is zero, the thread exits the monitor and is no longer its owner. Other threads that are blocking to enter the monitor are allowed to attempt to do so.`       

翻译:

        执行monitorexit的线程必须是objectref所对应的monitor的所有者。

        指令执行时,monitor的进入数减1,如果减1后进入数为0,则线程退出monitor,不再是这个monitor的所有者。此时,其他被这个monitor阻塞的线程可以尝试去获取这个 monitor 的所有权。

        Synchronized的语义底层是通过一个monitor的对象来完成,其实wait/notify等方法也依赖于monitor对象,这就是为什么只有在同步的块或者方法中才能调用wait/notify等方法,否则会抛出java.lang.IllegalMonitorStateException的异常的原因。

http://www.tj-hxxt.cn/news/92556.html

相关文章:

  • 有一个域名做网站优化seo网站
  • 做房源网站十大免费网站推广
  • 宝塔面板做网站合肥百度推广公司哪家好
  • 内蒙古做网站上海谷歌推广
  • 加强理想信念教育主题网站建设网络宣传方案
  • 做网站怎么回本百度竞价排名榜
  • 深圳出台多个利好政策seo推广营销公司
  • 检测软件定制seo基础知识
  • 京东网站建设2022年最新最有效的营销模式
  • 济南比较大的网站制作公司泰安网络推广培训
  • 腾讯企业邮箱注册申请官网东莞seo优化公司
  • 做废钢那个网站好东莞seo网站管理
  • 做时时彩网站数据分析师
  • 网站怎么做404 301今日小说搜索百度风云榜
  • 培训机构前端班课哈尔滨seo推广
  • 做网站一天忙吗关键词优化
  • 网站开发时seo专员工资待遇
  • html5 网站建设三只松鼠网络营销案例分析
  • 婺源网站建制作优化 保证排名
  • avada主题做网站seo关键词怎么选择
  • 做pc端网站效果兰州网络推广与营销
  • 业务宣传网站建设seo推广软件
  • 哈尔滨网站制作费用网上营销
  • 做网站插背景图片如何变大关键词seo排名优化如何
  • wordpress多站点不同主题网络营销策划创意案例点评
  • 怎么做好邯郸网站建设广州seo网站公司
  • 网站制作加教程视频成都百度搜索排名优化
  • 那个b2b网站可以做外贸seo网站管理招聘
  • 导购网站怎么推广在线资源搜索引擎
  • 做t恤网站 一件也可以做企业员工培训内容及计划