0
代码在我的服务器:如何防止客户端崩溃时事务死锁?
TransactionContext txCxt = hz.newTransactionContext(txop);
txCxt.beginTransaction();
TransactionalMap<Object, Object> map = txCxt.getMap(NearCacheTest.MAP);
try {
String tmp = String.valueOf(System.currentTimeMillis());
map.put("1", tmp); // reader1 is blocked
tmp = String.valueOf(System.currentTimeMillis());
map.put("2", tmp); // reader2 is blocked
// evict all client map cache
IList<Object> evictList = hz.getList(NearCacheTest.SEMAPHORE_EVICT);
evictList.add("1");
evictList.add("2");
int size = hz.getClientService().getConnectedClients().size();
hz.getSemaphore(NearCacheTest.SEMAPHORE_EVICT).release(size);
hz.getAtomicLong(NearCacheTest.SEMAPHORE_EVICT).set(size);
logger.info("client count:{}", size);
// wait to response from clients
logger.info("waiting for event:{}", NearCacheTest.SEMAPHORE_ACK);
hz.getSemaphore(NearCacheTest.SEMAPHORE_ACK).acquire();
我的问题是: 当一个客户端崩溃了,semaphore_ack
永远不能被释放;
我该怎么做才能防止死锁?