Java – Distributed counting semaphores in Java

Distributed counting semaphores in Java… here is a solution to the problem.

Distributed counting semaphores in Java

I’m looking for a distributed semaphore implementation similar to the java.util.concurrent.Semaphore concept (using postgres/zookeeper as storage) It will maintain a set of licenses that will use 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.

Related Problems and Solutions