What is AbstractQueuedSynchronizer
in Java's concurrent.locks
package used for? Can someone shed some light on its methods doAcquireInterruptibly
and parkAndCheckInterrupt
?
AbstractQueuedSynchronizer: It provides a framework for implementing blocking locks and related synchronizers like semaphores, CountDownLatch etc. The basic algorithm for acquire is try acquire, if successful return else enqueue thread, if it is not already queued and block the current thread. Similarly basic algorithm for release is try release, if successful, unblock the first thread in the queue else simply return. The threads will wait in a first-in-first-out (FIFO) wait queues. The abstract methods tryAcquire and tryRelease will be implemented by subclasses based on their need.
doAcquireInterruptibly will try to acquire the lock. If the lock is already acquired by some other thread, the current thread will be blocked(parked). If it acquires the lock, it will simply return.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With