1. Explanation
Because the lock holder is the thread, not the call. Thread A has locked the LoggingWidget instance object and can continue to unlock it if necessary! This is the reentrancy built into the lock.
2. Example
public class Widget { // 锁住了 public synchronized void doSomething() { ... } } public class LoggingWidget extends Widget { // 锁住了 public synchronized void doSomething() { System.out.println(toString() + ": calling doSomething"); super.doSomething(); } }
Collections in Java are mainly divided into four categories:
1 , List list: ordered, repeatable;
2, Queue queue: ordered, repeatable;
3, Set collection: non-repeatable;
4. Map mapping: unordered, unique keys, but not unique values.
The above is the detailed content of Example analysis of reentrancy of java built-in locks. For more information, please follow other related articles on the PHP Chinese website!