Synchronized usage based on java, using ynchronized
First, reference: http://www.cnblogs.com/devinzhang/archive/2011/12/14/2287675.html
PS: The reference article is very long, but the content is very rich. If you are a beginner, you must read it with patience.
Second, my personal summary:
The role of the synchronized keyword:
1. In all the synchronized methods of an object, only one unique thread can access these synchronized methods at a certain time point.
2. If a method is synchronized, the synchronized keyword indicates locking the current object (this.
3. If a synchronized method is static, the synchronized keyword indicates locking the class object corresponding to the current object. (No matter how many objects are generated, each class has only one class object)
4. multithreading: if it is a member variable: multiple threads will share; if it is a local variable, multiple threads will not share
How to Use the synchronized keyword in Java?
In my understanding
Sychronized is used to prevent more than two threads from simultaneously accessing the same resource during concurrency. The parameters are used for identification. For example, in the first case: When a function sychronized (object A) and B function sychronized (object B) Call function, other threads can no longer access function a, but can access function B. The second case: When a function sychronized (object A) and B function sychronized (Object A) Call function a in a thread, other functions cannot access function, and cannot access function B.
Please correct me.
In java, how to use synchronized?
Synchronized is a synchronous consciousness,
The first is the synchronous method, that is, only one thread can operate on this method at the same time,
Type 2 synchronized (this ){
Read ();
Update ();}
Is a synchronization block,