导致Hazelcast在map.lock()期间抛出InterruptedException的原因

时间:2015-09-02 17:04:05

标签: hazelcast

我正在使用IMap进行锁定,遵循如何解释:
https://groups.google.com/forum/#!topic/hazelcast/9YFGh3xwe8I

IMap<Object, Object> locks = hazelcastInstance.getMap("locks");
locks.lock(someStr);
try {
    //do stuff
} finally {
    locks.unlock(someStr);
}

偶尔,行

locks.locks(someStr)

导致错误

com.hazelcast.core.HazelcastException: java.lang.InterruptedException:
Call BasicInvocation{ serviceName='hz:impl:lockService',op=com.hazelcast.concurrent.lock.operations.LockOperation{
serviceName='hz:impl:lockService', callId=2854669, invocationTime=1441146297670, waitTimeout=-900001, callTimeout=60000}, 
partitionId=215, replicaIndex=0, tryCount=250, tryPauseMillis=500, invokeCount=0, callTimeout=60000, 
target=Address[*.*.*.*]:****, backupsExpected=0, backupsCompleted=0} was interrupted
at com.hazelcast.util.ExceptionUtil.rethrow(ExceptionUtil.java:52)
at com.hazelcast.spi.impl.BasicInvocationFuture.getSafely(BasicInvocationFuture.java:200)
at com.hazelcast.concurrent.lock.LockProxySupport.lock(LockProxySupport.java:79)
at com.hazelcast.concurrent.lock.LockProxySupport.lock(LockProxySupport.java:73)
at com.hazelcast.map.impl.proxy.MapProxyImpl.lock(MapProxyImpl.java:256)

Production中的集群包含两个节点。

我无法在本地重现此问题 我读过类似的例外情况,它与应用程序服务器时钟时间有关,导致两个远远不同步,但对我来说情况并非如此。

任何人都可以解释为什么会这样吗? 似乎我对IMap的使用非常简单。

1 个答案:

答案 0 :(得分:0)

通常InterruptedException表示正在执行locks.lock(someStr);的线程从程序的其他某个线程中断。

例如,您可以使用Thread.interrupt(),Future.cancel(true)或ExecutorService.shutdownNow()中断另一个线程。