Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@SessionScoped
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