Java High concurrency synchronized
Synchronized can guarantee that the code block or method at run time, only one method can enter the critical area at the same time, also can guarantee the memory visibility of the shared variable.
Synchronized can be used in three situations:
1. Normal synchronization method, lock is the current instance object
2. Static synchronization method, lock is the class object of the current classes
3. Synchronization method block, lock is the object inside the parentheses
Package Com.tianmaying.crawler.impl; Public class synchronizedtest { publicsynchronizedvoid test1 () {}}
public void Test2 () {
Synchronized (this) {}
}
public static synchronized void Test3 () {}
To decompile a project using Javap-c synchronizedtest
It can be seen that:
Synchronous methods, synchronous static methods: All are labeled the method is synchronized, and there is no special label, but according to the article "http://www.cnblogs.com/javaminer/p/3889023.html", means that the method of access The synchronized flag position for the _flags field is 1
--------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- ------------------------
Two concepts: Java object header, monitor
Java High concurrency synchronized