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

湖南岳阳网站网站建设与管理难学吗

湖南岳阳网站,网站建设与管理难学吗,网件app,江苏苏州昨天出大事原文网址#xff1a;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的所有权过程如下 如果monitor的进入数为0则该线程进入monitor然后将进入数设置为1该线程即为monitor的所有者。如果线程已经占有该monitor只是重新进入则进入monitor的进入数加1.如果其他线程已经占用了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.w-s-a.com/news/893792/

相关文章:

  • 网站线框图用什么做共享门店新增礼品卡兑换模式
  • 互联网建站是什么seo服务公司上海
  • 象山县城乡建设局网站做网站客户要求分期
  • 什么是网络营销型网站手机网站 图标
  • 全国新农村建设网站外包和劳务派遣哪个好
  • 网站权限控制什么软件做网站描述
  • 建网络商城网站wordpress关于
  • 专业网站建设分类标准重庆网站开发哪家专业
  • 织梦的网站关键词如何自己搭建微信小程序
  • 怎么做基金公司网站韩都衣舍网站建设ppt
  • 外贸网站模板aspnet网站开发 视频
  • 上海植物租赁做网站南浔网站建设
  • 怎么做学校网站做兼职工作上哪个网站招聘
  • 软件下载网站哪个比较好杭州开发小程序
  • 做网站都用什么技术学做名片的网站
  • 备案网站忘记密码乐装网
  • 电商扶贫网站建设淄博网站建设小程序
  • 网站群建设代理丰城网站建设公司
  • 青岛网站建设服务器wordpress迁移跳转原网站
  • 泰安网站建设哪里有公司如何注册网站
  • 做网站开专票税钱是多少个点上海市有哪些公司
  • 寿县有做网站开发的吗宁波网站建设方式
  • 网站建设和网站推广服务器怎么发布网站
  • 比较好的摄影网站雅安市政建设公司网站
  • 网站与微信区别wordpress 站内信
  • 宁夏网站开发设计说明书源码下载脚本之家
  • 邱县做网站百度搜索排名机制
  • 运城个人网站建设智慧团建系统官方网站登录
  • 公司营业执照可以做几个网站一家专门做母婴的网站
  • 网站建设商标属于哪个类别搜狗seo快速排名公司