Distributed counting semaphores in Java
I’m looking for a distributed semaphore implementation similar to the java.util.concurrent.Semaphore concept (using
It will maintain a set of licenses that will use postgres
/zookeeper
as storage) acquire().
Get and release with release(),
which allows me to restrict access to certain resources or synchronize certain resource executions. The only difference is that this semaphore should allow me to do all of this across multiple JVMs.
If there is any such implementation in Java or any reference algorithm used to implement the same, can someone point me out?
Solution
For zookeepers, you can use Apache Curator provides libraries that share semaphore abstractions.
In Postgres, you might consider using advisory locks for this and implementing an application class library on top of that.