作为这个问题的解答,我在Windows 7上使用JDK 6.0,并尝试使用信号量作为同步机制来解决我的同步问题。它完美地工作,但我正在尝试避免在我的问题中繁忙等待。
我只想询问Java文档并减少SO的麻烦,但文档是这样的:
我只想询问Java文档并减少SO的麻烦,但文档是这样的:
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