Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
public class ConversationLocks implements Serializable {
private final ConcurrentHashMap<String, Lock> conversationLocks = new ConcurrentHashMap<>();
public Lock get(String cid) {
ReentrantLock newLock = new ReentrantLock();
Lock alreadyAvailableLock = conversationLocks.putIfAbsent(cid, newLock);
return alreadyAvailableLock == null ? newLock : alreadyAvailableLock;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment