Quantcast
Channel: Java ConcurrentHashMap and synchronization - Stack Overflow
Browsing index pages (3 articles)

Java ConcurrentHashMap and synchronization

Let's say that I have a ConcurrentHashMap of clients registered to a server (inside a class Server):Map<ClientID, String> registeredClients = new ConcurrentHashMap<ClientID, String>();In my...

View Article


Answer by P.J.Meisch for Java ConcurrentHashMap and synchronization

If you are using Java 8, you can check with the following code:registeredClients.computeIfAbsent(client, c -> {throw new UnknownClientException();});The check if the key exists and the execution of...

View Article


Answer by Giovanni for Java ConcurrentHashMap and synchronization

No you don't have to synchonize the containsKey api if the Class is ConcurrentHashMap because as stated in the documentation its operations are thread safe (You can read all the documentation in order...

View Article
Browsing index pages (3 articles)


Latest Images