1. Problem solving
Multithreading concurrency issues.
2. Principle
3. Attention Points
A. What is the difference between a. Synchronized (class, this, object)?
Synchronized (class) is very special and allows another thread to wait in any place where it needs to get the class as monitor. class and this can be used at the same time .
1. For the instance synchronization method, lock the current instance object;
2. For the static synchronization method, lock the current object's class object;
3. For the method synchronization block, synchronized locks the object that is configured in parentheses.
Class and this are several cases:
Synchronized (Class)
Synchronized (This)
Threads each get monitor, do not wait;
Synchronized (This)
Synchronized (This)
If a different thread monitors the same instance object, it waits, and if a different instance, it does not wait;
Synchronized (Class)
Synchronized (Class)
If different threads listen to the same instance or different instance objects, they will wait.
Java synchronized (1)