java中的synchronized关键字是如何实现的? [英] How synchronized keyword in java have been implemented?

查看:25
本文介绍了java中的synchronized关键字是如何实现的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读操作系统,但遇到了几个进程间通信问题.这些可以通过使用 monitor 概念来解决,java 通过 synchronized 关键字.

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.

我想知道 synchronized 关键字是如何实现的?我试图查看来源,但我无法找到它.synchronized 是否正在使用像 down up (信号量基本上使用的)这样的系统调用来监视锁?

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?

JVM 在这个过程中是否有帮助?

Does JVM help in this process?

我是 Java 的新手,我想在进入 Java 中的线程概念之前知道事情是如何工作的.

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

提前致谢.

推荐答案

没有定义同步是如何实现的,只定义了它是如何工作的.

How synchronized is implemented is not defined, only how it works.

在许多 JVM 中,优化其行为是非常复杂的(例如,它试图避免进行系统调用,因为这些调用相对较慢)例如,如果 JIT 确定了这一点,它可以结合或消除与同步关键字的锁定可以做到.

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.

这篇关于java中的synchronized关键字是如何实现的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆