gpt4 book ai didi

java - 以下情况会导致死锁吗?

转载 作者:行者123 更新时间:2023-12-02 03:16:06 24 4
gpt4 key购买 nike

假设当前线程持有锁,那么同一个线程调用

synchronize(lock)

再说一遍,会发生死锁吗?

我依稀记得锁对于同一个线程是可重入的,什么意思?

最佳答案

来自documentation :

Thread cannot acquire a lock owned by another thread. But a thread can acquire a lock that it already owns. Allowing a thread to acquire the same lock more than once enables reentrant synchronization. This describes a situation where synchronized code, directly or indirectly, invokes a method that also contains synchronized code, and both sets of code use the same lock.

关于java - 以下情况会导致死锁吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10967866/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com