Are BlockingQueues and specifically ArrayBlockingQueues, implemented using semaphores in java? Do they use the same concept internally?
Asked
Active
Viewed 67 times
-1
-
4The JDK comes with the sources. Have you checked them out? – SurfMan Feb 09 '18 at 13:04
-
Please clarify your efforts. What you searched, what you found and what is the question that needs to be answered. What do you mean by the same concept? The concept of Semaphores? – Spyros K Feb 09 '18 at 13:04
1 Answers
0
Different JDKs may have different implementations. The OpenJDK does not use semaphores for the implementation of ArrayBlockingQueue. However you should specifically check the implementation you are interested as it is possible to develop an ArrayBlockingQueue using semaphores.
See the following link for different implementations of ArrayBlockingQueue. Grepcode:ArrayBlockingQueue
OpenJDK vesion 8u40-b25 uses Locks (ReentrantLocks actually) which is a different concept. You can see the sources in this link.
ArrayBlockingQueue - OpenJDK
See this article on Locks VS Semaphores: Binary Semaphore vs a ReentrantLock

Spyros K
- 2,480
- 1
- 20
- 37