com.hazelcast.core.IMap.unlock()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(4.7k)|赞(0)|评价(0)|浏览(137)

本文整理了Java中com.hazelcast.core.IMap.unlock()方法的一些代码示例,展示了IMap.unlock()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IMap.unlock()方法的具体详情如下:
包路径:com.hazelcast.core.IMap
类名称:IMap
方法名:unlock

IMap.unlock介绍

[英]Releases the lock for the specified key. It never blocks and returns immediately.

If the current thread is the holder of this lock, then the hold count is decremented. If the hold count is zero, then the lock is released. If the current thread is not the holder of this lock, then IllegalMonitorStateException is thrown.

Warning:

This method uses hashCode and equals of the binary form of the key, not the actual implementations of hashCode and equalsdefined in the key's class.
[中]释放指定钥匙的锁。它从不阻塞并立即返回。
如果当前线程是此锁的保持器,则保持计数将递减。如果保持计数为零,则释放锁。如果当前线程不是此锁的持有者,则抛出IllegalMonitorStateException。
警告:
此方法使用密钥二进制形式的hashCode和equals,而不是密钥类中定义的hashCode和equals的实际实现。

代码示例

代码示例来源:origin: rancher/cattle

@Override
public void unlock() {
  map.unlock(key);
}

代码示例来源:origin: hazelcast/hazelcast-jet

@Override
public void unlock(K key) {
  map.unlock(key);
}

代码示例来源:origin: dsukhoroslov/bagri

@SuppressWarnings({ "unchecked", "rawtypes" })
protected <K> void unlock(Map<K, ?> cache, K key) {
  ((IMap) cache).unlock(key);
}

代码示例来源:origin: hazelcast/hazelcast-jet

@Override
public void unlock(String mapName, String key) {
  hazelcast.getMap(mapName).unlock(key);
}

代码示例来源:origin: com.hazelcast/hazelcast-all

@Override
public void unlock(String mapName, String key) {
  hazelcast.getMap(mapName).unlock(key);
}

代码示例来源:origin: hazelcast/hazelcast-code-samples

public void run() {
    IMap map = hazelcast.getMap("myMap");
    int key = random.nextInt(SIZE);
    map.lock(key);
    try {
      Thread.sleep(1);
    } catch (InterruptedException e) {
      throw new RuntimeException(e);
    } finally {
      map.unlock(key);
    }
  }
}, 1);

代码示例来源:origin: org.apache.camel/camel-hazelcast

/**
 * UPDATE an object in your cache (the whole object will be replaced)
 */
private void update(Object oid, Exchange exchange) {
  Object body = exchange.getIn().getBody();
  this.cache.lock(oid);
  this.cache.replace(oid, body);
  this.cache.unlock(oid);
}

代码示例来源:origin: org.apache.camel/camel-hazelcast

/**
 * Replaces the entry for given id with a specific value in the body, only if currently mapped to a given value
 */
private void update(Object oid, Object ovalue, Exchange exchange) {
  Object body = exchange.getIn().getBody();
  this.cache.lock(oid);
  this.cache.replace(oid, ovalue, body);
  this.cache.unlock(oid);
}

代码示例来源:origin: org.meridor.perspective/perspective-backend-common

@Override
public <K, T> void modifyMap(String mapId, K key, Consumer<Map<K, T>> action) {
  IMap<K, T> map = getMap(mapId);
  map.lock(key, lockTimeout, TimeUnit.MILLISECONDS);
  try {
    action.accept(map);
  } finally {
    map.unlock(key);
  }
}

代码示例来源:origin: org.meridor.perspective/perspective-backend-common

@Override
public <K, I, O> O readFromMap(String mapId, K key, Function<Map<K, I>, O> function) {
  IMap<K, I> map = getMap(mapId);
  map.lock(key, lockTimeout, TimeUnit.MILLISECONDS);
  try {
    return function.apply(map);
  } finally {
    map.unlock(key);
  }
}

代码示例来源:origin: org.apache.camel/camel-hazelcast

@Override
public boolean add(String key) {
  repo.lock(key);
  try {
    return repo.putIfAbsent(key, false) == null;
  } finally {
    repo.unlock(key);
  }
}

代码示例来源:origin: org.apache.camel/camel-hazelcast

@Override
public boolean contains(String key) {
  repo.lock(key);
  try {
    return this.repo.containsKey(key);
  } finally {
    repo.unlock(key);
  }
}

代码示例来源:origin: hazelcast/hazelcast-jet

protected void handleMapUnlock(String[] args) {
  getMap().unlock(args[1]);
  println("true");
}

代码示例来源:origin: org.apache.camel/camel-hazelcast

@Override
public boolean confirm(String key) {
  repo.lock(key);
  try {
    return repo.replace(key, false, true);
  } finally {
    repo.unlock(key);
  }
}

代码示例来源:origin: org.apache.camel/camel-hazelcast

@Override
public boolean remove(String key) {
  repo.lock(key);
  try {
    return repo.remove(key) != null;
  } finally {
    repo.unlock(key);
  }
}

代码示例来源:origin: hazelcast/hazelcast-jet

protected void handleMapUnlock(String[] args) {
  getMap().unlock(args[1]);
  println("true");
}

代码示例来源:origin: com.hazelcast/hazelcast-all

protected void handleMapUnlock(String[] args) {
  getMap().unlock(args[1]);
  println("true");
}

代码示例来源:origin: com.hazelcast/hazelcast-all

protected void handleMapUnlock(String[] args) {
  getMap().unlock(args[1]);
  println("true");
}

代码示例来源:origin: io.skullabs.kikaha/kikaha-hazelcast

@Override
public Session createOrRetrieveSession( HttpServerExchange exchange ) {
  final String sessionId = retrieveSessionIdFrom( exchange );
  Session session = getSessionFromCache( sessionId );
  if ( session == null ) {
    sessionCache.lock(sessionId);
    try { session = tryToCreateAndStoreNewSession(sessionId, exchange); }
    finally { sessionCache.unlock(sessionId); }
  }
  return session;
}

代码示例来源:origin: com.hazelcast.simulator/tests-common

@TimeStep
public void timeStep(ThreadState state) {
  int key = state.randomInt(keyCount);
  long increment = state.randomInt(100);
  map.lock(key);
  try {
    Long current = map.get(key);
    map.put(key, current + increment);
    state.increments[key] += increment;
  } finally {
    map.unlock(key);
  }
}

相关文章