Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Distributed counting semaphore in Java

I am looking for a distributed semaphore implementation (with postgres / zookeeper as store) that is similar to the concept of java.util.concurrent.Semaphore which will maintain a set of permits that will be taken using acquire() and released with release() allowing me to restrict access to some resource or synchronize some execution. The only difference is that this semaphore should allow me to do all these actions across multiple jvms.

Can someone point to me if there is any such implementation in java or any reference algorithm for implementing the same?

like image 444
tuk Avatar asked Apr 24 '26 14:04

tuk


1 Answers

For zookeeper you can use apache Curator library that provides Shared Semaphore abstraction.

In postgres you might consider using Advisory Locks for this and implement an applicative kind of library on top of that.

like image 52
Mark Bramnik Avatar answered Apr 26 '26 05:04

Mark Bramnik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!