Hazelcast distributed lock does not work

I am trying to test the implementation of distributed locking, but I still have not found a way to make it work. I deployed the REST service using two simple methods, for example:

@GET
@Path("/lock")
@Produces("text/*")
public String lock() throws InterruptedException {
    Lock lock = distributedService.getDistributedLock("test");
    boolean result = lock.tryLock(5, TimeUnit.SECONDS);
    return result ? "locked" : "timeout";
}

@GET
@Path("/unlock")
@Produces("text/*")
public String unlock() {
    Lock lock = distributedService.getDistributedLock("test");
    lock.unlock();
    return "unlocked";
}

The sharedService object implements the getDistributedLock () method:

@Override
public Lock getDistributedLock(String lockName) {
    return Hazelcast.getDefaultInstance().getLock(lockName);
}

In the hazelcast.xml file, I turned on the TCP-IP connection and disabled everything else:

<network>
<port auto-increment="true">5701</port>
<join>
  <multicast enabled="false" />
  <tcp-ip enabled="true">
    <interface>192.168.0.01</interface>
    <interface>192.168.0.02</interface>
  </tcp-ip>
</join>
<interfaces enabled="false" />
<symmetric-encryption enabled="false" />
<asymmetric-encryption enabled="false" />

, IP-, .xml(192.168.0.01 192.168.0.02), . ( "" ), , unlock(), ( "" ), , , lock(), . , unlock() .

- Distributed Lock ?

+3
1

. , REST . , , , . . .

+7

All Articles