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

Example analysis of reentrancy of java built-in locks

WBOY
Release: 2023-04-30 11:22:06
forward
992 people have browsed it

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

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template