1、java中的每个对象都可作为锁,有三种表现形式:

对于普通方法,锁的是当前this对象。

对于静态方法,锁的是class对象

对于方法块,锁的是synchronized指定的对象。

2、JVM基于Monitor对象来实现昂发的同步和代码块同步,但是实现细节不一样。代码块同步是使用monitorenter和monitorexit指令实现,而方法同步使用的是另外一种方式实现的。

3、Java's monitor supports two kinds of thread synchronization: mutual exclusion and cooperation.

4、synchronized锁不一定是FIFO的。

it might make sense to have ten FIFO queues, one for each priority a thread can have inside the Java virtual machine. The virtual machine could then choose the thread that has been waiting the longest in the highest priority queue that contains any waiting threads. 、

5、每个对象和每个Class对象都有与其对应的监视器对象

In the Java virtual machine, every object and class is logically associated with a monitor. For objects, the associated monitor protects the object's instance variables. For classes, the monitor protects the class's class variables. If an object has no instance variables, or a class has no class variables, the associated monitor protects no data.

6、抛异常的时候锁会自动退出

7、方法块和方法锁的字节码区别见http://www.artima.com/insidejvm/ed2/threadsynchP.html

方法块有monitorenter和monitorexit指令

方法没有

1、If you compare these bytecodes with the ones shown earlier for KitchenSync's reverseOrder() method, you will see that these bytecodes are in effect those of KitchenSync with the support for entering and exiting the monitor removed. 2、Instructions at offset 0 through 56 of HeatSync's bytecodes correspond to instructions at offset 4 through 68 of KitchenSync's bytecodes. Because HeatSync's reverseOrder() method doesn't need a local variable slot to store the reference to the locked object, the local variable positions used by each method are different. The function of the instructions themselves, however, match up exactly.

3、Another difference between the two reverseOrder() methods is that the compiler doesn't create an exception table for HeatSync's reverseOrder() method. In HeatSync's case, an exception table isn't necessary. When this method is invoked, the Java virtual machine automatically acquires the lock on the this object. If this method completes abruptly, just as if it completes normally, the virtual machine will release the lock on the this object automatically.

8、

synzhronized原理3的更多相关文章

  1. synchronized原理

    http://www.cnblogs.com/YDDMAX/p/5658607.html http://www.cnblogs.com/YDDMAX/p/5658668.html synzhroniz ...

  2. 奇异值分解(SVD)原理与在降维中的应用

    奇异值分解(Singular Value Decomposition,以下简称SVD)是在机器学习领域广泛应用的算法,它不光可以用于降维算法中的特征分解,还可以用于推荐系统,以及自然语言处理等领域.是 ...

  3. node.js学习(三)简单的node程序&&模块简单使用&&commonJS规范&&深入理解模块原理

    一.一个简单的node程序 1.新建一个txt文件 2.修改后缀 修改之后会弹出这个,点击"是" 3.运行test.js 源文件 使用node.js运行之后的. 如果该路径下没有该 ...

  4. 线性判别分析LDA原理总结

    在主成分分析(PCA)原理总结中,我们对降维算法PCA做了总结.这里我们就对另外一种经典的降维方法线性判别分析(Linear Discriminant Analysis, 以下简称LDA)做一个总结. ...

  5. [原] KVM 虚拟化原理探究(1)— overview

    KVM 虚拟化原理探究- overview 标签(空格分隔): KVM 写在前面的话 本文不介绍kvm和qemu的基本安装操作,希望读者具有一定的KVM实践经验.同时希望借此系列博客,能够对KVM底层 ...

  6. H5单页面手势滑屏切换原理

    H5单页面手势滑屏切换是采用HTML5 触摸事件(Touch) 和 CSS3动画(Transform,Transition)来实现的,效果图如下所示,本文简单说一下其实现原理和主要思路. 1.实现原理 ...

  7. .NET Core中间件的注册和管道的构建(1)---- 注册和构建原理

    .NET Core中间件的注册和管道的构建(1)---- 注册和构建原理 0x00 问题的产生 管道是.NET Core中非常关键的一个概念,很多重要的组件都以中间件的形式存在,包括权限管理.会话管理 ...

  8. python自动化测试(2)-自动化基本技术原理

    python自动化测试(2) 自动化基本技术原理 1   概述 在之前的文章里面提到过:做自动化的首要本领就是要会 透过现象看本质 ,落实到实际的IT工作中就是 透过界面看数据. 掌握上面的这样的本领 ...

  9. CRC、反码求和校验 原理分析

    3月份开始从客户端转后台,算是幸运的进入全栈工程师的修炼阶段.这段时间一边是老项目的客户端加服务器两边的维护和交接,一边是新项目加加加班赶工,期间最长经历了连续工作三天只睡了四五个小时的煎熬,人生也算 ...

随机推荐

  1. 一个简单的SqlServer游标使用

    declare @id int ) declare c_department cursor for select id,name from department open c_department f ...

  2. 查看GCC编译C的中间代码

    小测试,记录一下命令 XD 一.C程序源码(code.c): 二.中间代码 由 gcc -fdump-tree-all code.c 得到 查看 code.c.012t.cfg 三.汇编级代码 (64 ...

  3. SQL Server访问MySql

    使用环境:操作系统:window7数据库:SQL Server2005.MySql5.01.在安装了SQL Server的服务器上安装MySql的ODBC驱动:下载链接:http://dev.mysq ...

  4. 用wget下载文件

    wget使用文档:https://www.gnu.org/software/wget/manual/wget.html 最开始常用的比如: wget -O  /e/movie.mp4 http://w ...

  5. portable runtime

    APR The mission of the Apache Portable Runtime (APR) project is to create and maintain software libr ...

  6. Mac OS 快捷键

    系统 (Option+) Command+Space 切换输入法 Command+Tab 切换不同应用 Command+Tab 切换一个应用内的不同窗口 Command+Shift+3 截取整个屏幕 ...

  7. thinkphp四种url访问方式详解

    本文实例分析了thinkphp的四种url访问方式.分享给大家供大家参考.具体分析如下: 一.什么是MVC thinkphp的MVC模式非常灵活,即使只有三个中和一个也可以运行. M -Model 编 ...

  8. Flink - DataStream

    先看例子, final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); D ...

  9. JS中基本window.document对象操作以及常用事件!

    一.找到元素 1.document.getELementById("id"):根据id找,最多找一个. var a=document.getELementById("id ...

  10. php + ajax + html 简单跨域问题

    XMLHttpRequest cannot load http://localhost:8080/abc/index.php. No 'Access-Control-Allow-Origin' hea ...