How to detect deadlock ? Timeout in synchronized block?

后端 未结 7 2118
北荒
北荒 2020-12-29 09:00

I’m debugging a Java application that runs several threads. After a while of watching the log it seems that one of those threads is not running anymore. My guess is that the

7条回答
  •  没有蜡笔的小新
    2020-12-29 09:28

    You can't use timeouts with traditionally synchronized methods. However, using the "new" java.util.concurrent stuff, you can use programatic locks that have timeout support.

    For example, look at java.util.concurrent.locks.ReentrantLock

    A reentrant mutual exclusion Lock with the same basic behavior and semantics as the implicit monitor lock accessed using synchronized methods and statements, but with extended capabilities.

提交回复
热议问题