What does "synchronized" mean in Java?
This question already has an answer here:
There is no synchronized
keyword in C++.
There is one in Java, though, where for methods it means the following two things:
Similar rules apply to arbitrary blocks.
Also, I recommend learning from a peer-reviewed book, not some arbitrary non-authoritative website.
In the (Java) example
public static synchronized Singleton getInstance()
means that only one thread at a time should be able to access the getInstance() method this to avoid a racing condition.
As the commenters already pointed out, synchronized is a Java keyword.
It means that two threads cannot execute the method at the same time and the JVM takes care of enforcing that.
In C++, you will have to use some synchronization construct, like a critical section or a mutex. You can consult this.
链接地址: http://www.djcxy.com/p/91850.html上一篇: Java中的同步方法是什么?
下一篇: 在Java中“同步”是什么意思?