正如問題所在。我在Windows 7上使用JDK 6.0,並試圖使用信號作爲解決同步問題的機制。它完美地工作,但我試圖避免忙於等待我的問題。Java信號量默認使用忙等待還是等待/通知?
我只想問Java文檔和割捨這麼麻煩,但該文檔是這樣的:
Acquires the given number of permits from this semaphore,
blocking until all are available, or the thread is interrupted.
Acquires the given number of permits, if they are available,
and returns immediately, reducing the number of available permits
by the given amount.
If insufficient permits are available then the current thread
becomes disabled for thread scheduling purposes and lies dormant
http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/Semaphore.html#acquire(int)
也就是說,該文檔似乎在暗示兩個答案。哪一個是正確的?
大部分'java.util.concurrent'原語都依賴於基於park/unpark的'java.util.concurrent.locks.AbstractQueuedSynchronizer',即沒有繁忙的旋轉 – bestsss 2011-12-26 03:20:07