Java 同步静态方法:锁定对象或类 [英] Java synchronized static methods: lock on object or class

查看:27
本文介绍了Java 同步静态方法:锁定对象或类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java 文档说:

不可能在同一台机器上两次调用同步方法同一对象交错.

It is not possible for two invocations of synchronized methods on the same object to interleave.

这对静态方法意味着什么?既然静态方法没有关联对象,那么synchronized关键字会锁定类而不是对象吗?

What does this mean for a static method? Since a static method has no associated object, will the synchronized keyword lock on the class, instead of the object?

推荐答案

由于静态方法没有关联对象,synchronized 关键字会锁定类而不是对象吗?

是的.:)

这篇关于Java 同步静态方法:锁定对象或类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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