Java如何实现让执行某个“同步”一个方法一次仅一个线程?
JVM如何允许?我不明白。
我的假设是,我们创建的所有线程实际上都位于一个单个Java线程后面,该线程管理后背后线程在处理器中实际执行的线程。但是,就像您没有平行执行一样,我认为这不是会发生的事情。
否则,如果不是这样(因此,线程不在一个Java线程后面,而是独立的),那么如何创建两个线程,例如在这一刻,这两个线程都在两个CPU内部,并且想要访问相同的线程方法,请注意而不访问该方法?我认为必须有一些控制。该同步如何完成?
How can JVM allow this? I don't understand it.
My hypothesis is that the all threads that we create are actually behind one single Java thread that manage which and how the behind thread actually executes in the processor. But this way it's like you don't have parallel execution, which I don't think is what happens I guess.
Otherwise, if it's not that(and so the threads are not behind one Java thread, but they are independent), how can two created threads that are for example in that moment at the same time both inside two CPUs and want to access the same method, be aware of it and not access the method? I think there must be something that controls that. How is this synchronization done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论