我是Java新手,正在尝试学习同步的概念.我在Java Tutorial Oracle中看到了这个引用.我正在努力通过短语“类对象”来理解它们所指的是什么.什么是类对象?
You might wonder what happens when a static synchronized method is
invoked, since a static method is associated with a class, not an
object. In this case, the thread acquires the intrinsic lock for the
Class object associated with the class. Thus access to class’s static
fields is controlled by a lock that’s distinct from the lock for any
instance of the class.
解决方法:
Class本身就是一个类.您可以通过以下方式获取类实例
>呼叫例如String.class(如果您静态地知道该类),它是Class< String>的实例.
>调用someInstance.getClass()(如果你想要一个实例的具体类),这是一个Class< ;?的实例扩展SomeInstance>,假设someInstance是SomeInstance类型的引用(绑定是因为它可能是SomeInstance的子类).
标签:java,multithreading
来源: https://codeday.me/bug/20190829/1760148.html