Hazelcast文档显示您可以使用分布式Hazelcast作为客户端,并提到如果持有锁的成员断开连接 - 锁将被释放。但是,如果我将锁用作客户端,则不会将其视为“成员” - 如果客户端断开连接,是否仍会安全地释放锁?
答案 0 :(得分:1)
将自动释放客户端锁定。尝试以下程序,你会发现自己。
public class Main {
public static void main(String[] args) throws InterruptedException {
HazelcastInstance hz1 = Hazelcast.newHazelcastInstance();
HazelcastInstance client = HazelcastClient.newHazelcastClient();
client.getLock("clientLock").lock();
System.out.println("is locked:" + hz1.getLock("clientLock").isLocked());
client.shutdown();
System.out.println("Client is shutdown");
for(;;){
boolean isLocked = hz1.getLock("clientLock").isLocked();
if(!isLocked){
System.out.println("Client lock is released");
return;
}
System.out.println("is locked:"+ isLocked);
Thread.sleep(1000);
}
}
}