Search code examples
hazelcast

How to use distributed lock in Hazelcast Community Edition?


My current development environment is mac, java 21, spring boot 3.3.3, maven.3.x. To use only the features of hazelcast Community Edition ( https://hazelcast.com/community-edition-projects/downloads/ ), I have added the dependency as below.

<dependency>
    <groupId>com.hazelcast</groupId>
    <artifactId>hazelcast-all</artifactId>
    <version>4.2.8</version>
</dependency>

To use Hazelcast's distributed lock, I coded it like this

………..
………..

    FencedLock lock = hzInstance.getCPSubsystem().getLock(lockKey);
    boolean isLocked = lock.tryLock(timeout, unit);
………..
………..

From the page below, it seems that distributed locking using CP Subsystem is only available for Enterprise Edition. Am I right? https://hazelcast.com/products/feature-comparison/

If I'm right, how can I use hazelcast's distributed lock using Community Edition?

Thanks.

I followed the documentation below and implemented it.

https://docs.hazelcast.com/imdg/4.2/data-structures/fencedlock


Solution

  • Quoting from Changes to Community Edition of Hazelcast Platform

    As a result, the existing CP Subsystem will be deprecated from the Community Edition and will no longer be supported as of Hazelcast Platform 5.5.

    So if you are using an older version of hazelcast you can still use CP Subsystem with Community Edition.

    Note : hazelcast-all is very old. It belongs to Hazelcast version 4

    You can use version 5.4 which is newer than 4.2 and still has CP subsystem

    <dependency>
        <groupId>com.hazelcast</groupId>
        <artifactId>hazelcast</artifactId>
        <version>5.4.0</version>
    </dependency>