Distributed counting semaphore in Java

江枫思渺然 提交于 2021-02-10 06:00:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!