Java中的分布式计数信号量 [英] Distributed counting semaphore in Java

查看:223
本文介绍了Java中的分布式计数信号量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种分布式信号量实现(以postgres/zookeeper作为存储),该实现类似于java.util.concurrent.Semaphore的概念,该概念将维护一组许可,这些许可将使用acquire()获取并发布使用release()允许我限制对某些资源的访问或同步某些执行.唯一的区别是,此信号量应允许我跨多个jvm执行所有这些操作.

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.

如果在Java中有任何此类实现或用于实现该实现的任何引用算法,有人可以指向我吗?

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

推荐答案

对于动物园管理员,您可以使用

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

在postgres中,您可以考虑为此使用咨询锁,并在其之上实现一种可应用的库.

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

这篇关于Java中的分布式计数信号量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆