简体   繁体   English

如何实现java中的synchronized关键字?

[英]How synchronized keyword in java have been implemented?

I'm reading operating system and I came across several problems for inter-process communication. 我正在阅读操作系统,我遇到了几个进程间通信问题。 These can be solved by using monitor concepts which java provide via synchronized keyword. 这些可以通过使用java通过synchronized关键字提供的监视器概念来解决。

I wish to know how synchronized keyword have been implemented? 我想知道synchronized关键字是如何实现的? I tried to look at the source but I couldn't able to find it. 我试着查看源代码但我无法找到它。 Are synchronized are using system calls like down up ( which semaphore uses basically) to monitor the locks? 正在synchronized使用系统调用,就像down up (这旗语使用基本)来监视锁吗?

Does JVM help in this process? JVM是否有助于此过程?

I'm a novice in Java, I wish to know how things works before I go into thread concepts in java. 我是Java的新手,我希望在进入java中的线程概念之前知道事情是如何工作的。

Thanks in advance. 提前致谢。

How synchronized is implemented is not defined, only how it works. 未定义如何实现同步,仅定义它的工作方式。

In many JVMs, what it does is quite complicated to optimise its behaviour (for example it tries to avoid making system calls as these are relatively slow) For example the JIT can combine or eliminate locking with the synchronized keyword if it determines this can be done. 在许多JVM中,优化其行为是非常复杂的(例如,它试图避免进行系统调用,因为它们相对较慢)例如,如果确定可以完成,则JIT可以使用synchronized关键字组合或消除锁定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM