2016 - 2024

感恩一路有你

synchronized三种用法 java synchronized锁对象,当对象引用是null的时候,锁的是什么?

浏览量:1732 时间:2021-03-14 06:39:06 作者:admin

java synchronized锁对象,当对象引用是null的时候,锁的是什么?

谢邀!

Java语言规范中明确指出如果锁住的对象是null,则会NullPointerException,规范内容如下:

The type of Expression must be a reference type, or a compile-time error occurs. A synchronized statement is executed by first evaluating the Expression. Then: If evaluation of the Expression completes abruptly for some reason, then the synchronized statement completes abruptly for the same reason. Otherwise, if the value of the Expression is null, a NullPointerException is thrown.

synchronized三种用法 synchronized和lock区别 synchronized锁升级过程

版权声明:本文内容由互联网用户自发贡献,本站不承担相关法律责任.如有侵权/违法内容,本站将立刻删除。