簡體   English   中英

Java:為什么該線程已經持有鎖時要等待?

[英]Java: Why does this thread wait when it already holds the lock?

這是轉儲中的單個線程,它說明了問題。 沒有其他線程持有鎖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)方法。

您將看到它旨在:

等待此ServiceTracker至少跟蹤一項服務。

所以這不是鎖爭用-底層系統使用鎖來等待東西-在大多數情況下,這實際上是一個好主意。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM