分布式锁服务

发布于 2024-07-25 22:25:20 字数 1433 浏览 6 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

夕色琉璃 2024-08-01 22:25:20

hazelcast 是一个新人。 我一直在使用它,它的使用和配置非常简单。

据我所知,Gigaspaces 和 hazelcast 之间不应该有任何冲突,因为 hazelcast 没有任何依赖项,即没有 jgroups.jar 等

Hazelcast

  1. 互斥(锁定),是的实现java.util.concurrency.locks.Lock
  2. 在一定超时后自动锁释放,是的,如果成员离开集群,所有锁都会被释放
  3. Java 实现,是
  4. 的 很高兴有:.Net 实现,不是纯java解决方案,可能可以移植到j#
  5. 如果它是免费的:死锁检测/缓解,不,我的Hazelcast没有做出任何努力来处理这个
  6. 简单的部署,它是一个带有单个配置文件的单个jar,作为应用程序的一部分部署,不需要额外的过程

A newer kid on the block is hazelcast. I've been playing with it and it is amazingly simple to use and configure.

As far as I can see there shouldn't be any conflict between Gigaspaces and hazelcast as hazelcast doesn't have any dependencies i.e. no jgroups.jar etc

Hazelcast:

  1. A mutual exclusion (lock), yep implementation of java.util.concurrency.locks.Lock
  2. Automatic lock release after a certain timeout, yep all locks are released if a member leaves the cluster
  3. Java implementation, yep
  4. Nice to have: .Net implementation, nope is a pure java solution, might be possible to port to j#
  5. If it's free: Deadlock detection / mitigation, nope no effort is made my Hazelcast to handle this
  6. Easy deployment, it's a single jar with a single config file, deployed as part of your application, no additional processes are required
定格我的天空 2024-08-01 22:25:20

查看 Apache 的 Zookeeper(Hadoop 子项目) - 它提供分布式同步。 文档不是很好,但是它看起来是一个有趣的产品 - 查看食谱以获取有关如何使用 Zookeeper 的想法。

它的级别比您可能想要的要低,并且确实需要额外的部署,因为它建议使用专用服务器。

您可以对不同的锁定策略进行建模,它确实为锁持有者死亡(临时节点)提供了解决方案。

Check out Apache's Zookeeper (A Hadoop sub-project) - it offers distributed synchronization. The documentation isn't great, but what there is makes it look an interesting product - checkout the recipes for ideas on how to use Zookeeper.

It is lower-level than you'd probably want and it does require additional deployment as it recommends dedicated servers.

You can model different locking strategies and it does offer a solution for a lock holder dying (ephemeral nodes).

风筝在阴天搁浅。 2024-08-01 22:25:20

Teracotta(包括开源版本)通过使用任一 synchronizedjava.util.concurrent.ReentrantReadWriteLock - 后者显然符合您的要求。


更新

由于问题现在添加了与 GigaSpaces“混合”的要求,我要说不要将它们混合。 它只会增加您的技术堆栈的复杂性,并增加以下工作量:

  • 代码和基础设施方面的集成;
  • 管理它们之间的同步;
  • 学习/调整/调试 Teracotta。

将更好地用于创建或实施基于 GigaSpaces 的锁定解决方案。

Teracotta, including the Open Source edition, has distributed locking semantics by using either synchronized or the java.util.concurrent.ReentrantReadWriteLock - the latter apparently fitting your requirements.


Update

Since the question now added the requirement of 'mixing' with GigaSpaces, I'm going to say don't mix them. It's just going to add more complexity to your technological stack, and the effort of:

  • integrating, in terms of both code and infrastructure;
  • managing synchronisation between them;
  • learning/tuning/debugging Teracotta.

will be better spent creating or implementing a locking solution based on GigaSpaces.

飘落散花 2024-08-01 22:25:20

我建议使用 Redisson 它是一个 Redis 基于内存数据网格。 它实现了熟悉的 Java 数据结构,包括分布式 java.util.Lock 和 java.util.concurrent.ReentrantReadWriteLock 对象。 包括设置租用时间的能力。 Lock 使用示例:

Redisson redisson = Redisson.create(config);

Lock lock = redisson.getLock("anyLock");
try {
   // unlock automatically after 10 seconds of hold
   lock.lock(10, TimeUnit.SECONDS);

} finally {
   lock.unlock();
}

...

redisson.shutdown();

支持 Azure 和 AWS 等云供应商。

I recommend to use Redisson it's a Redis based on In-Memory Data Grid. It implements familiar Java data structures including distributed java.util.Lock and java.util.concurrent.ReentrantReadWriteLock objects. Including ability to setup leaseTime. Lock usage example:

Redisson redisson = Redisson.create(config);

Lock lock = redisson.getLock("anyLock");
try {
   // unlock automatically after 10 seconds of hold
   lock.lock(10, TimeUnit.SECONDS);

} finally {
   lock.unlock();
}

...

redisson.shutdown();

Supports cloud vendors like Azure and AWS.

蓝海似她心 2024-08-01 22:25:20

ZooKeeper 的帮助下,ZooKeeper 成为分布式锁定的事实上的标准。 apache.org/index.html" rel="nofollow">Apache Curator 框架。 查看 recipes 中的锁以获取更多信息。

ZooKeeper became a de facto standard in distributed locking with the help of Apache Curator framework. Check out the locks in recipes for more information.

从来不烧饼 2024-08-01 22:25:20

Oracle Coherence 非常稳定和成熟,包括互斥支持:

  cache.lock(key, -1);
    try {
      // .. add your critical code here
    } finally {
      cache.unlock(key);
    }

锁可以承受服务器故障、滚动重新启动等。

为了充分披露,我在 Oracle 工作。 这篇文章中表达的意见和观点是我自己的,并不一定反映我的雇主的意见或看法。

Oracle Coherence, which is very stable and mature, includes mutual exclusion support:

  cache.lock(key, -1);
    try {
      // .. add your critical code here
    } finally {
      cache.unlock(key);
    }

Locks survive server failures, rolling re-starts, etc.

For the sake of full disclosure, I work at Oracle. The opinions and views expressed in this post are my own, and do not necessarily reflect the opinions or views of my employer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文