Deep analysis of Java synchronized implementation principle
•
Java
Implementation principle of Java synchronized
public class SynchronizedTest { public synchronized void test1(){ } public void test2(){ synchronized (this){ } } }
1) Synchronous code block
2) Synchronization method
Java object header
Mark Word
Monitor
Lock optimization
Spin lock
Adaptive spin lock
Lock elimination
public void vectortest(){ Vector<String> vector = new Vector<String>(); for(int i = 0 ; i < 10 ; i++){ vector.add(i + ""); } System.out.println(vector); }
Lock coarsening
Lightweight Locking
Bias lock
Heavyweight lock
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码