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

编程入门 行业动态 更新时间:2024-10-22 23:03:32
本文介绍了java中的synchronized关键字是如何实现的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在阅读操作系统,但遇到了几个进程间通信问题.这些可以通过使用 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屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 14:11:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1410163.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何实现   关键字   java   synchronized

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!