问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/59658786/distributed-counting-semaphore-in-java