Are BlockingQueues and specifically ArrayBlockingQueues, implemented using semaphores in java? Do they use the same concept internally?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.