java - synchronized同步问题
PHP中文网
PHP中文网 2017-04-18 10:50:07
0
3
660

一个类中有两个同步方法,此时有多个线程同时访问该对象的两个方法,这样会造成锁互斥吗?

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(3)
Ty80

Yes, it is this object that is locked, not a method.

黄舟

Yes, if it is a static method, the class is locked, that is, all instances of the class can only be accessed by one person. If it is a normal method, the object is locked.

PHPzhong

The synchronized keyword locks the object, that is, the object lock. The static method can be considered to obtain the lock of the corresponding Class object. When multiple threads compete for the lock of an object, only one will get the lock.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!