Home  >  Article  >  Java  >  Example analysis of reentrancy of java built-in locks

Example analysis of reentrancy of java built-in locks

WBOY
WBOYforward
2023-04-30 11:22:06947browse

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();
}
}

What collection classes are there in Java?

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!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete