gpt4 book ai didi

Java:为什么这个线程在已经持有锁的情况下还要等待?

转载 作者:行者123 更新时间:2023-12-01 14:45:56 24 4
gpt4 key购买 nike

这是来自转储的单个线程,说明了该问题。没有其他线程持有锁 0x00000007d7f78430 但它仍在等待。

"main" prio=6 tid=0x000000000033b800 nid=0x2478 in Object.wait() [0x000000000257d000]          java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000007d7f78430> (a org.osgi.util.tracker.ServiceTracker$AllTracked)
at org.osgi.util.tracker.ServiceTracker.waitForService(ServiceTracker.java:456)
- locked <0x00000007d7f78430> (a org.osgi.util.tracker.ServiceTracker$AllTracked)
at org.apache.camel.test.blueprint.CamelBlueprintHelper.getOsgiService(CamelBlueprintHelper.java:190)
at org.apache.camel.test.blueprint.CamelBlueprintHelper.getOsgiService(CamelBlueprintHelper.java:165)
at org.apache.camel.test.blueprint.CamelBlueprintTestSupport.createCamelContext(CamelBlueprintTestSupport.java:116)
at org.apache.camel.test.junit4.CamelTestSupport.doSetUp(CamelTestSupport.java:247)
at org.apache.camel.test.junit4.CamelTestSupport.setUp(CamelTestSupport.java:217)
at org.apache.camel.test.blueprint.CamelBlueprintTestSupport.setUp(CamelBlueprintTestSupport.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

最佳答案

看看org.osgi.util.tracker.ServiceTracker.waitForService(long timeout)方法。

您将看到它的设计目的是:

Wait for at least one service to be tracked by this ServiceTracker.

所以这不是锁争用 - 底层系统正在使用锁来等待东西 - 这在大多数情况下实际上是一个非常好的主意。

关于Java:为什么这个线程在已经持有锁的情况下还要等待?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15437366/

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