How synchronized keyword in java have been implemented?

Deadly 提交于 2020-01-13 10:56:13

问题


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.

I wish to know how synchronized keyword have been implemented? 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?

Does JVM help in this process?

I'm a novice in Java, I wish to know how things works before I go into thread concepts in java.

Thanks in advance.


回答1:


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.



来源:https://stackoverflow.com/questions/12365127/how-synchronized-keyword-in-java-have-been-implemented

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!